如何存储加速度计值

发布于 2024-11-16 03:45:08 字数 1405 浏览 3 评论 0 原文

我有这个代码:

public class Chronom extends Activity 
{

    Chronometer mChronometer;
    ProgressBar progre;

    int total=1;


    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        //layout
        setContentView(R.layout.main7watingscreen);

        //Start Chronometer
        mChronometer = (Chronometer) findViewById(R.id.chrono1);
        mChronometer.start();

        progre = (ProgressBar) findViewById(R.id.progressBar1);

        MyCount counter = new MyCount(31000,300);
        counter.start();
    }


    public class MyCount extends CountDownTimer
        {
            public MyCount(long millisInFuture, long countDownInterval) 
            {
                super(millisInFuture, countDownInterval);
            }
            @Override
            public void onFinish() 
            {
                Intent myIntent = new Intent( Chronom.this, MainMenu.class);
                startActivityForResult(myIntent, 0);
            }
            @Override
            public void onTick(long millisUntilFinished) 
            {
                total++;
                progre.setProgress(total);         
            }   

        }

我想将加速度计值(x,y和z)存储在一个向量中(可以是其他形式,我想知道你的意见)。

但我想在进度条满的同时执行此操作(30 秒后停止)。比如1秒开始存储,30秒后停止。

如果您不明白我的问题,请说出来,我会更好地解释。

怎么办呢??请帮忙!

I have this code:

public class Chronom extends Activity 
{

    Chronometer mChronometer;
    ProgressBar progre;

    int total=1;


    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        //layout
        setContentView(R.layout.main7watingscreen);

        //Start Chronometer
        mChronometer = (Chronometer) findViewById(R.id.chrono1);
        mChronometer.start();

        progre = (ProgressBar) findViewById(R.id.progressBar1);

        MyCount counter = new MyCount(31000,300);
        counter.start();
    }


    public class MyCount extends CountDownTimer
        {
            public MyCount(long millisInFuture, long countDownInterval) 
            {
                super(millisInFuture, countDownInterval);
            }
            @Override
            public void onFinish() 
            {
                Intent myIntent = new Intent( Chronom.this, MainMenu.class);
                startActivityForResult(myIntent, 0);
            }
            @Override
            public void onTick(long millisUntilFinished) 
            {
                total++;
                progre.setProgress(total);         
            }   

        }

and i want to store accelerometer values (x, y and z) inside a vector for example (can be other form i want to know your opinion).

But i want to do this at the same time as the progress bar is fulling ( it stops after 30 sec). Like begin the storing at 1 sec and stop after 30 sec.

If you don't understand my question please say it and i will explain it better.

How to do it?? Please help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听闻余生 2024-11-23 03:45:08

每次更改传感器值时,您都可以通过 onSensorChanged() 回调获取传感器值(请参阅 SensorListener 参考)。 无法在设定的时间查询传感器数据

有一种解决方法:让侦听器在每次更改时保存值(即在 onSensorChanged() 方法内),并使用计时器查询这些保存的值。例如,您可以使用static float[] 数组或SharedPreferences 值。

You obtain sensor values every time they're changed, through the onSensorChanged() callback (see the SensorListener reference). You can't query the sensor data at a set time.

There is a way around that: have a listener saving the values every time they change (i.e., inside the onSensorChanged() method), and query those saved values using your timer. For example, you can use a static float[] array for it or SharedPreferences values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文