在Android上间隔运行应用程序中更改周期

时间:2015-06-01 20:08:39

标签: android

我正在尝试在Android Studio中为Interval Running编写一个应用程序。我有一个算法应用程序的问题。首先,我将编写应用程序应该做的事情。 间隔运行以不同的速度运行,速度越来越慢。我的应用程序将告诉跑步者他现在应该做什么 - 跑得快,跑得慢,走路等等 - 某种助手。在申请中我们输入热身(我们在几秒钟之前行走的时间),放松(我们在最后几秒钟后行走的时间),他的速度(一个高速运行周期持续多少秒),低速(一个周期多少秒)低速运行持续时间和循环(速度 - 低速循环次数)。一切都显示在这张照片上。

http://oi62.tinypic.com/66dphw.jpg

应用程序窗口(抱歉我的油漆语言编辑不好):

http://oi59.tinypic.com/2v2gza1.jpg

START后点击所有计算开始。 总时间正确计算。剩下的时间(从总时间到0)也没问题。当循环次数为1时,一切正常。如果我想要更多的低速 - 空速循环,应用程序工作不正确,我无法弄清楚如何编写这种代码的和平以使其工作。有人可以用这个来打扰我吗?

源代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    b1=(Button)findViewById(R.id.button2);
    b2=(Button)findViewById(R.id.button3);
    b3=(Button)findViewById(R.id.button4);
    am=(AudioManager)getSystemService(Context.AUDIO_SERVICE);

    b1.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            am.setRingerMode(0);
        }
    });
    b2.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            am.setRingerMode(1);
        }
    });
    b3.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            am.setRingerMode(2);
        }
    });
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}


public void start(View view) {

    EditText editText = (EditText) findViewById(R.id.editText);
    warmup = Integer.parseInt(editText.getText().toString());
    EditText editText2 = (EditText) findViewById(R.id.editText2);
    relax = Integer.parseInt(editText2.getText().toString());
    EditText editText3 = (EditText) findViewById(R.id.editText3);
    hispeed = Integer.parseInt(editText3.getText().toString());
    EditText editText4 = (EditText) findViewById(R.id.editText4);
    lowspeed = Integer.parseInt(editText4.getText().toString());
    EditText editText5 = (EditText) findViewById(R.id.editText5);
    cykle = Integer.parseInt(editText5.getText().toString());

    overall = warmup + relax + ((hispeed + lowspeed) * cykle);
    TextView textView13 = (TextView) findViewById(R.id.textView13);
    textView13.setText("" + overall);


    final TextView textView12 = (TextView) findViewById(R.id.textView12);
    CountDownTimer Count = new CountDownTimer(overall * 1000, 1000) {

        public void onTick(long millisUntilFinished) {

   //         int seconds = (int) ((millisUntilFinished / 1000));

            textView12.setText("" + millisUntilFinished / 1000);

            int milis = (int) millisUntilFinished / 1000;

            if ((overall - milis) < warmup) {
                TextView textView8 = (TextView) findViewById(R.id.textView8);
                textView8.setText("Warmup");
                                                 }
            if (((overall - milis) < warmup+hispeed) && ((overall - milis) > (warmup))){
                TextView textView8 = (TextView) findViewById(R.id.textView8);
                textView8.setText("HiSpeed");
            }
            if (((overall - milis) < warmup+hispeed+lowspeed) && ((overall - milis) > (warmup+hispeed))){
                TextView textView8 = (TextView) findViewById(R.id.textView8);
                textView8.setText("LowSpeed");
            }

            if ((overall - milis) > (overall - relax)) {
                TextView textView8 = (TextView) findViewById(R.id.textView8);
                textView8.setText("Relax");
            }





        }
        public void onFinish() {

            textView12.setText("0");
            TextView textView8 = (TextView) findViewById(R.id.textView8);
            textView8.setText("Finish");
        }
    };

    Count.start();

    }

}

0 个答案:

没有答案