Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将持续时间设置为用户摇晃手机时的持续时间_Java_Android_Android Studio - Fatal编程技术网

Java 如何将持续时间设置为用户摇晃手机时的持续时间

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

我希望下面代码中的振动和GIF视图的持续时间与用户摇晃手机的持续时间相同。一旦用户停止摇晃手机,我就想进行另一项活动。以下是我的代码(包括注释): {

这是用户摇晃手机时执行的代码:

        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) {

    }
};