title: How Do I Set Duration to last As Long as the User Shakes Their Phone
body: <p>I want vibration and the GIF view in the code below to have the same duration the user shakes their phone. Once the user stops shaking their phone, I want to go to another activity. Here is my code (includes comments):
  {</p>
  
  <pre><code>private SensorManager shakeEvent;
  private float acelVal;
  private float acelLast;
  private float shake;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      Fresco.initialize(this);
      setContentView(R.layout.activity_animation);
  
      shakeEvent = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
      shakeEvent.registerListener(sensorListener, shakeEvent.getDefaultSensor
              (Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
  
      acelVal = SensorManager.GRAVITY_EARTH;
      acelLast = SensorManager.GRAVITY_EARTH;
      shake = 0.00f;
  
  }
  
  private final SensorEventListener sensorListener = new SensorEventListener() {
      @Override
      public void onSensorChanged(SensorEvent sensorEvent) {
  
          float x = sensorEvent.values[0];
          float y = sensorEvent.values[1];
          float z = sensorEvent.values[2];
  
          acelLast = acelVal;
          acelVal = (float)Math.sqrt((double)(x*x + y*y + z*z));
          float delta = acelVal - acelLast;
          shake = shake * 0.9f + delta;
  </code></pre>
  
  <p>This is the code executed when the user shakes their phone:</p>
  
  <pre><code>        if (shake &gt; 12){
              SimpleDraweeView gifAnimation = (SimpleDraweeView) findViewById(R.id.gifAnimation);
  
              DraweeController controller = Fresco.newDraweeControllerBuilder()
                      .setUri("http://i.imgur.com/XHpujBO.gif")
                      .setAutoPlayAnimations(true)
                      .build();
  
              gifAnimation.setController(controller);
  
              //I want this GIF to last as long as the user shakes their phone
  
              Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
              vibrator.vibrate(2000); //Want to change duration to be the same as the shaking
  
              //I want this code to be executed once the shaking stops
              /*Intent intent = new Intent(getApplicationContext(),MainActivity.class);
              startActivityForResult(intent,0);*/
  
          }
      }
  
      @Override
      public void onAccuracyChanged(Sensor sensor, int i) {
  
      }
  };
  </code></pre>
  
  <p>}</p>