Android Vibrator - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Vibrator class.

This code example shows how to use the following methods:vibrate
	public void vibrate(long pattern){
        // Start the vibration, 0 defaults to half a second. 
		if (pattern == 0)
			pattern = 500;
        Vibrator vibrator = (Vibrator) mCtx.getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(pattern);
	} 
	 
	public String getPlatform()
	{ 
		return this.platform;
	} 
	 
	public String getUuid()
	{		 
		TelephonyManager operator = (TelephonyManager) mCtx.getSystemService(Context.TELEPHONY_SERVICE);
		String uuid = operator.getDeviceId();
		return uuid;
	} 
	 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:vibrate
        // Make a Toast, using the current context as returned by the Context Provider 
        Toast.makeText(application, "Astroboy says, \"" + something + "\"", Toast.LENGTH_LONG).show();
    } 
 
    public void brushTeeth() { 
        vibrator.vibrate(new long[]{0, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50,  }, -1);
    } 
 
    public String punch() {
        final String expletives[] = new String[]{"POW!", "BANG!", "KERPOW!", "OOF!"};
        return expletives[random.nextInt(expletives.length)];
    } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
import android.widget.Toast; 
 
public class PlatLogoActivity extends Activity {
    Toast mToast;
    ImageView mContent;
    Vibrator mZzz = new Vibrator();
    int mCount;
    final Handler mHandler = new Handler();
 
    Runnable mSuperLongPress = new Runnable() {
        public void run() { 
            mCount++; 
            mZzz.vibrate(50 * mCount); 
            final float scale = 1f + 0.25f * mCount * mCount; 
            mContent.setScaleX(scale); 
            mContent.setScaleY(scale); 
 
            if (mCount <= 3) { 
                mHandler.postDelayed(mSuperLongPress, ViewConfiguration.getLongPressTimeout()); 
            } else { 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:vibrate, sleep
            } 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 Vibrator();
            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 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:cancel
    if (player != null) {
      Log.d(TAG, "Stopping ringer");
      player.stop();
    } 
    Log.d(TAG, "Cancelling vibrator" );
    vibrator.cancel();
  } 
 
  private boolean shouldVibrate() { 
    if(player == null) {
      return true; 
    } 
 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      return shouldVibrateNew(context);
    } 
    return shouldVibrateOld(context);
  } 
 
  @SuppressLint("NewApi") 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:vibrate
      * Vibrate for s seconds. 
      */ 
     public static void vibrate(double s) {
         Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
         if (v != null) {
             v.vibrate((int) (1000 * s));
         } 
     } 
 
     /** 
      * Get an Overview of all Hardware Sensors of an Android Device 
      */ 
     public static String getHardwareSensors() {
        SensorManager sm = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        List<Sensor> allSensors = sm.getSensorList(Sensor.TYPE_ALL);
 
        if (allSensors != null) {
            String resultString = "";
            for (Sensor s : allSensors) {
                resultString += String.format("Name=" + s.getName());
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:vibrate
    if (playBeep && mediaPlayer != null) {
      mediaPlayer.start();
    } 
    if (vibrate) {
      Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
      vibrator.vibrate(VIBRATE_DURATION);
    } 
  } 
 
  private static boolean shouldBeep(SharedPreferences prefs, Context activity) {
    boolean shouldPlayBeep = prefs.getBoolean(PreferencesActivity.KEY_PLAY_BEEP, true);
    if (shouldPlayBeep) {
      // See if sound settings overrides this 
      AudioManager audioService = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
      if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
        shouldPlayBeep = false;
      } 
    } 
    return shouldPlayBeep;
  } 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:vibrate
            0, 100, 10000 
    }; 
 
    static void vibrate(Context context) {
        Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(VIBRATION_PATTERN, -1);
    } 
 
    /* 
     * Writes an NdefMessage to a NFC tag 
     */ 
    static boolean writeTag(NdefMessage message, Tag tag) {
        int size = message.toByteArray().length;
        try { 
            Ndef ndef = Ndef.get(tag);
            if (ndef != null) {
                ndef.connect();
                if (!ndef.isWritable()) {
                    Log.e(TAG, "Tag is not writable!");
                    return false; 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:vibrate
 
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            boolean before = progress == 0, after = seekBar.getMax() == progress, middle = seekBar.getMax() / 2 ==
                    progress;
            if (before || after || middle) {
                vibrator.vibrate(17);
            } 
            // sadly makes the damn seekbar wiggle 
//            beforeTextView.setTypeface(before?boldTypeFace:defaultTypeface); 
//            afterTextView.setTypeface(after?boldTypeFace:defaultTypeface); 
            float unitProgress = unitProgress(seekBar);
 
            notifyTheOthers(unitProgress);
 
        } 
 
 
        private float unitProgress(SeekBar seekBar) {
            return ((float) seekBar.getProgress()) / seekBar.getMax();
        } 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:vibrate, sleep
            } 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 Vibrator();
            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 
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android Vibrator Questions & Answers:

See Code Examples for Android Vibrator Methods: