Search in sources :

Example 21 with Vibrator

use of android.os.Vibrator in project ChatExchange by HueToYou.

the class MainActivity method confirmClose.

public void confirmClose(View v) {
    if (mTabLayout.getSelectedTabPosition() != 0) {
        Vibrator vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        // Vibrate for 500 milliseconds
        vib.vibrate(100);
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                new AlertDialog.Builder(new ContextThemeWrapper(MainActivity.this, mUseDark ? R.style.Theme_AppCompat : R.style.Theme_AppCompat_Light)).setTitle(getResources().getText(R.string.activity_main_delete_chat_title)).setMessage(getResources().getText(R.string.activity_main_delete_chat_message)).setPositiveButton(getResources().getText(R.string.generic_yes), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (mTabLayout.getTabAt(mTabLayout.getSelectedTabPosition()).getTag() != null) {
                            mChatUrls.remove(mTabLayout.getTabAt(mTabLayout.getSelectedTabPosition()).getTag().toString());
                            mEditor.putStringSet("chatURLs", mChatUrls).apply();
                            TabLayout.Tab prev = mTabLayout.getTabAt(mTabLayout.getSelectedTabPosition() - 1);
                            mTabLayout.removeTab(mTabLayout.getTabAt(mTabLayout.getSelectedTabPosition()));
                            if (prev != null)
                                prev.select();
                        }
                    }
                }).setNegativeButton(getResources().getText(R.string.generic_no), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                }).show();
            }
        });
    }
}
Also used : ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) DialogInterface(android.content.DialogInterface) TabLayout(android.support.design.widget.TabLayout) Vibrator(android.os.Vibrator)

Example 22 with Vibrator

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

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

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

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.FP_SUCCESS_VIBRATE, 1, UserHandle.USER_CURRENT) == 1;
    if (vibrator != null && FingerprintVib) {
        vibrator.vibrate(FP_SUCCESS_VIBRATE_PATTERN, -1);
    }
}
Also used : Vibrator(android.os.Vibrator)

Example 24 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 25 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)

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