Java 如何将持续时间设置为用户摇晃手机时的持续时间
我希望下面代码中的振动和GIF视图的持续时间与用户摇晃手机的持续时间相同。一旦用户停止摇晃手机,我就想进行另一项活动。以下是我的代码(包括注释): { 这是用户摇晃手机时执行的代码:Java 如何将持续时间设置为用户摇晃手机时的持续时间,java,android,android-studio,Java,Android,Android Studio,我希望下面代码中的振动和GIF视图的持续时间与用户摇晃手机的持续时间相同。一旦用户停止摇晃手机,我就想进行另一项活动。以下是我的代码(包括注释): { 这是用户摇晃手机时执行的代码: if (shake > 12){ SimpleDraweeView gifAnimation = (SimpleDraweeView) findViewById(R.id.gifAnimation); DraweeController cont
if (shake > 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) {
}
};
}
if (shake > 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) {
}
};