Example usage for android.os Vibrator hasVibrator

List of usage examples for android.os Vibrator hasVibrator

Introduction

In this page you can find the example usage for android.os Vibrator hasVibrator.

Prototype

public abstract boolean hasVibrator();

Source Link

Document

Check whether the hardware has a vibrator.

Usage

From source file:Main.java

public static void vibrate(Context context) {
    Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    if (v.hasVibrator()) {
        v.cancel();/*from  ww  w . j  a va  2 s .c o  m*/
        v.vibrate(150);
    }
}

From source file:org.xbmc.kore.utils.UIUtils.java

public static void handleVibration(Context context) {
    if (context == null)
        return;/*  www . j  a va 2 s. co  m*/

    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    if (!vibrator.hasVibrator())
        return;

    //Check if we should vibrate
    boolean vibrateOnPress = PreferenceManager.getDefaultSharedPreferences(context)
            .getBoolean(Settings.KEY_PREF_VIBRATE_REMOTE_BUTTONS, Settings.DEFAULT_PREF_VIBRATE_REMOTE_BUTTONS);
    if (vibrateOnPress) {
        vibrator.vibrate(UIUtils.buttonVibrationDuration);
    }
}

From source file:org.ttrssreader.utils.Utils.java

/**
 * Alert the user by a short vibration or a flash of the whole screen.
 *///from ww w  .j a  v  a 2  s  . com
public static void alert(Activity activity, boolean error) {
    Vibrator vib = ((Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE));
    if (vib.hasVibrator()) {
        vib.vibrate(Utils.SHORT_VIBRATE);
    } else if (error) {
        // Only flash when user tried to move forward, flashing when reaching the last article looks just wrong.
        Animation flash = AnimationUtils.loadAnimation(activity, R.anim.flash);
        View main = activity.findViewById(R.id.frame_all);
        main.startAnimation(flash);
    }
}

From source file:paulscode.android.mupen64plusae.jni.CoreInterface.java

public static void registerVibrator(int player, Vibrator vibrator) {
    boolean hasVibrator = vibrator.hasVibrator();

    if (hasVibrator && player > 0 && player < 5) {
        sVibrators[player - 1] = vibrator;
    }/*  w w  w. ja va  2  s .c o  m*/
}

From source file:com.linkbubble.MainApplication.java

public static boolean handleBubbleAction(final Context context, BubbleAction action, final String urlAsString,
        long totalTrackedLoadTime) {
    Constant.ActionType actionType = Settings.get().getConsumeBubbleActionType(action);
    boolean result = false;
    if (actionType == Constant.ActionType.Share) {
        String consumePackageName = Settings.get().getConsumeBubblePackageName(action);
        CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString()
                + ", consumePackageName:" + consumePackageName);
        String consumeName = Settings.get().getConsumeBubbleActivityClassName(action);

        if (consumePackageName.equals(BuildConfig.APPLICATION_ID)
                && consumeName.equals(Constant.SHARE_PICKER_NAME)) {
            AlertDialog alertDialog = ActionItem.getShareAlert(context, false,
                    new ActionItem.OnActionItemSelectedListener() {
                        @Override
                        public void onSelected(ActionItem actionItem) {
                            Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType("text/plain");
                            intent.setClassName(actionItem.mPackageName, actionItem.mActivityClassName);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.putExtra(Intent.EXTRA_TEXT, urlAsString);
                            String title = MainApplication.sTitleHashMap != null
                                    ? MainApplication.sTitleHashMap.get(urlAsString)
                                    : null;
                            if (title != null) {
                                intent.putExtra(Intent.EXTRA_SUBJECT, title);
                            }/*from w  ww . j a  v a2s  . c o  m*/
                            context.startActivity(intent);
                        }
                    });
            Util.showThemedDialog(alertDialog);
            return true;
        }

        // TODO: Retrieve the class name below from the app in case Twitter ever change it.
        Intent intent = Util.getSendIntent(consumePackageName, consumeName, urlAsString);
        try {
            context.startActivity(intent);
            if (totalTrackedLoadTime > -1) {
                Settings.get().trackLinkLoadTime(totalTrackedLoadTime, Settings.LinkLoadType.ShareToOtherApp,
                        urlAsString);
            }
            result = true;
        } catch (ActivityNotFoundException ex) {
            Toast.makeText(context, R.string.consume_activity_not_found, Toast.LENGTH_LONG).show();
        } catch (SecurityException ex) {
            Toast.makeText(context, R.string.consume_activity_security_exception, Toast.LENGTH_SHORT).show();
        }
    } else if (actionType == Constant.ActionType.View) {
        String consumePackageName = Settings.get().getConsumeBubblePackageName(action);
        CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString()
                + ", consumePackageName:" + consumePackageName);
        result = MainApplication.loadIntent(context, consumePackageName,
                Settings.get().getConsumeBubbleActivityClassName(action), urlAsString, -1, true);
    } else if (action == BubbleAction.Close || action == BubbleAction.BackButton) {
        CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString());
        result = true;
    }

    if (result) {
        boolean hapticFeedbackEnabled = android.provider.Settings.System.getInt(context.getContentResolver(),
                android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) != 0;
        if (hapticFeedbackEnabled && action != BubbleAction.BackButton) {
            Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            if (vibrator.hasVibrator()) {
                vibrator.vibrate(10);
            }
        }
    }

    return result;
}

From source file:com.developer.shade.sensors.SensorService.java

private void onSystemVibrate(int milli) {
    Log.d("Running onSystem", "Running Internal Device Vibrator");
    Vibrator oVibrate = (Vibrator) getSystemService(VIBRATOR_SERVICE);
    if (oVibrate.hasVibrator()) {
        oVibrate.vibrate(milli);//from   w  ww  .  j a v a2  s  .co  m
    }
}

From source file:in.blogspot.anselmbros.torchie.ui.fragment.SettingsFragment.java

private void vibrate(long time) {
    Vibrator vib = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
    if (vib.hasVibrator())
        vib.vibrate(time);/* w  w  w .  jav  a2 s.c  o  m*/
}

From source file:com.android2.calculator3.EventListener.java

private void vibrate() {
    if (CalculatorSettings.vibrateOnPress(mContext)) {
        Vibrator vi = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
        if (!vi.hasVibrator())
            return;
        vi.vibrate(CalculatorSettings.getVibrationStrength());
    }/* w ww  . ja  v  a 2  s  .c o  m*/
}

From source file:ca.mudar.snoozy.receiver.PowerConnectionReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);

    // Get user preferences
    final SharedPreferences sharedPrefs = context.getSharedPreferences(Const.APP_PREFS_NAME,
            Context.MODE_PRIVATE);
    final SharedPreferences.Editor sharedPrefsEditor = sharedPrefs.edit();
    final boolean hasNotifications = sharedPrefs.getBoolean(Const.PrefsNames.HAS_NOTIFICATIONS, false);
    final boolean hasVibration = (sharedPrefs.getBoolean(Const.PrefsNames.HAS_VIBRATION, false)
            && vibrator.hasVibrator());
    final boolean hasSound = sharedPrefs.getBoolean(Const.PrefsNames.HAS_SOUND, false);
    final boolean onScreenLock = sharedPrefs.getBoolean(Const.PrefsNames.ON_SCREEN_LOCK, true);
    final boolean onPowerLoss = sharedPrefs.getBoolean(Const.PrefsNames.ON_POWER_LOSS, false);
    final int delayToLock = Integer.parseInt(
            sharedPrefs.getString(Const.PrefsNames.DELAY_TO_LOCK, Const.PrefsValues.DELAY_FAST)) * 1000;
    final int notifyCount = sharedPrefs.getInt(Const.PrefsNames.NOTIFY_COUNT, 1);
    final int notifyGroup = sharedPrefs.getInt(Const.PrefsNames.NOTIFY_GROUP, 1);

    final String action = intent.getAction();
    if (action == null)
        return;//from w w  w.  ja  v  a 2s . c o m

    if (action.equals(Const.IntentActions.NOTIFY_DELETE)) {
        if (hasNotifications) {
            // Reset the notification counter (and group) on NOTIFY_DELETE
            sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_COUNT, 1);
            sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_GROUP, notifyGroup + 1);
            sharedPrefsEditor.apply();
        }
    } else if (action.equals(Intent.ACTION_POWER_CONNECTED)
            || action.equals(Intent.ACTION_POWER_DISCONNECTED)) {
        final boolean isConnectedPower = action.equals(Intent.ACTION_POWER_CONNECTED);

        // Lock the screen, following the user preferences
        if (delayToLock == 0) {
            LockScreenHelper.lockScreen(context, onScreenLock, onPowerLoss, isConnectedPower);
        } else {
            Intent intentService = new Intent(Intent.ACTION_SYNC, null, context, DelayedLockService.class);
            Bundle extras = new Bundle();
            extras.putBoolean(Const.IntentExtras.ON_SCREEN_LOCK, onScreenLock);
            extras.putBoolean(Const.IntentExtras.ON_POWER_LOSS, onPowerLoss);
            extras.putBoolean(Const.IntentExtras.IS_CONNECTED, isConnectedPower);
            extras.putInt(Const.IntentExtras.DELAY_TO_LOCK, delayToLock);
            intentService.putExtras(extras);
            context.startService(intentService);
        }

        // Save in database
        saveHistoryItem(context.getApplicationContext(), isConnectedPower, notifyGroup);

        if (hasNotifications) {
            // Send notification, with sound and vibration
            notify(context, isConnectedPower, hasVibration, hasSound, notifyCount);

            // Increment the notification counter
            sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_COUNT, notifyCount + 1);
            sharedPrefsEditor.apply();
        } else {
            // Native Vibration or Sound, without Notifications
            nativeVibrate(context, hasVibration);

            nativeRingtone(context, hasSound);
        }
    }
}

From source file:com.rickendirk.rsgwijzigingen.ZoekService.java

private void vibrate() {
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    if (vibrator.hasVibrator()) {
        //Eerste waarde vertraging, 2e duur, 3e vertraging, 4e duur, etc
        long[] pattern = { 0, 250, 600, 250 };
        vibrator.vibrate(pattern, -1); // -1 betekent geen herhaling
    }//from w w w. j av  a 2s .c om
}