如何为我的安卓健身应用制作训练计划?

huangapple go评论82阅读模式
英文:

How to do sets for my android workout application?

问题

package com.example.workout_sure;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.example.workout_sure.Database.SWADB;
import com.example.workout_sure.Model.Exercise;
import com.example.workout_sure.Utils.Common;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import me.zhanghai.android.materialprogressbar.MaterialProgressBar;

public class Daily_Training extends AppCompatActivity {

    // ... (Previous code)

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

        initData();
        swaDB =  new SWADB(this);

        // ... (Previous code)

        btnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(btnStart.getText().toString().toLowerCase().equals("commencer"))
                {
                    showGetReady();
                    btnStart.setText("fini");
                }
                else if(btnStart.getText().toString().toLowerCase().equals("fini"))
                {
                    if(swaDB.getSettingMode() == 0)
                        exercisesEasyModeCountDown.cancel();
                    if(swaDB.getSettingMode() == 1)
                        exercisesMediumModeCountDown.cancel();
                    if(swaDB.getSettingMode() == 2)
                        exercisesHardModeCountDown.cancel();

                    restTimeCountDown.cancel();

                    if(ex_id < list.size())
                    {
                        showRestTime();
                        ex_id++;
                        progressBar.setProgress(ex_id);
                        txtTimer.setText("");
                    }
                    else
                        showFinished();
                }
                else
                {
                    if(swaDB.getSettingMode() == 0)
                        exercisesEasyModeCountDown.cancel();
                    if(swaDB.getSettingMode() == 1)
                        exercisesMediumModeCountDown.cancel();
                    if(swaDB.getSettingMode() == 2)
                        exercisesHardModeCountDown.cancel();
                    restTimeCountDown.cancel();

                    if(ex_id < list.size())
                        setExerciseInformation(ex_id);
                    else
                        showFinished();
                }
            }
        });
    }

    private void showExercises() {
        if(ex_id < list.size())  //list size y'a ts les exos
        {
            for (int i = 0; i < 3; i++) {
                ex_image.setVisibility(View.VISIBLE);
                btnStart.setVisibility(View.VISIBLE);
                layoutGetReady.setVisibility(View.INVISIBLE);
                detail_text.setVisibility(View.VISIBLE);

                ex_image.setImageResource(list.get(ex_id).getImage_id());
                ex_name.setText(list.get(ex_id).getName());
                detail_text.setText(list.get(ex_id).getDetail());

                showRestTime();
            }
        }
        else
            showFinished();
    }

    // ... (Remaining code)
}
英文:

first thanks to read this.
I did a workout app for my team, inspired by a yoga app tutorial. My problem is in the yoga app you don't have many sets, just one, and i would like to add sets. I tried to make a for(int i = 0; i &lt; 50; i++) in my ShowExercises but it didn't work and i would like to have the exercise and the rest repeated, not just the exercise.
Here is my code,


import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.example.workout_sure.Database.SWADB;
import com.example.workout_sure.Model.Exercise;
import com.example.workout_sure.Utils.Common;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
public class Daily_Training extends AppCompatActivity {
Button btnStart;
ImageView ex_image;
TextView txtGetReady,txtCountdown,txtTimer,ex_name,detail_text;
ProgressBar progressBar;
LinearLayout layoutGetReady;
int ex_id=0,limit_time=0;
List&lt;Exercise&gt; list = new ArrayList&lt;&gt;();
SWADB swaDB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily__training);
initData();
swaDB =  new SWADB(this);
btnStart = (Button)findViewById(R.id.btnStart);
ex_image = (ImageView)findViewById(R.id.detail_image);
detail_text = (TextView)findViewById(R.id.detail_text);
txtCountdown = (TextView)findViewById(R.id.txtCountdown);
txtGetReady = (TextView)findViewById(R.id.txtGetReady);
txtTimer = (TextView)findViewById(R.id.timer);
ex_name = (TextView)findViewById(R.id.title);
layoutGetReady = (LinearLayout)findViewById(R.id.layout_get_ready);
progressBar = (MaterialProgressBar)findViewById(R.id.progressBar);
//Set data
progressBar.setMax(list.size());
setExerciseInformation(ex_id);
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(btnStart.getText().toString().toLowerCase().equals(&quot;commencer&quot;))
{
showGetReady();
btnStart.setText(&quot;fini&quot;);
}
else if(btnStart.getText().toString().toLowerCase().equals(&quot;fini&quot;))
{
if(swaDB.getSettingMode() == 0)
exercisesEasyModeCountDown.cancel();
if(swaDB.getSettingMode() == 1)
exercisesMediumModeCountDown.cancel();
if(swaDB.getSettingMode() == 2)
exercisesHardModeCountDown.cancel();
restTimeCountDown.cancel();
if(ex_id &lt; list.size())
{
showRestTime();
ex_id++;
progressBar.setProgress(ex_id);
txtTimer.setText(&quot;&quot;);
}
else
showFinished();
}
else
{
if(swaDB.getSettingMode() == 0)
exercisesEasyModeCountDown.cancel();
if(swaDB.getSettingMode() == 1)
exercisesMediumModeCountDown.cancel();
if(swaDB.getSettingMode() == 2)
exercisesHardModeCountDown.cancel();
restTimeCountDown.cancel();
if(ex_id &lt; list.size())
setExerciseInformation(ex_id);
else
showFinished();
}
}
});
}
private void showRestTime() {
ex_image.setVisibility(View.INVISIBLE);
btnStart.setText(&quot;Passer&quot;);
btnStart.setVisibility(View.VISIBLE);
txtTimer.setVisibility(View.INVISIBLE);
detail_text.setVisibility(View.INVISIBLE);
layoutGetReady.setVisibility(View.VISIBLE);
restTimeCountDown.start();
txtGetReady.setText(&quot;TEMPS DE REPOS&quot;);
}
private void showGetReady() {
ex_image.setVisibility(View.INVISIBLE);
btnStart.setVisibility(View.INVISIBLE);
txtTimer.setVisibility(View.VISIBLE);
detail_text.setVisibility(View.INVISIBLE);
layoutGetReady.setVisibility(View.VISIBLE);
txtGetReady.setText(&quot;PREPARE TOI&quot;);
new CountDownTimer(6000,1000)
{
@Override
public void onTick(long millisUntilFinished) {
txtCountdown.setText(&quot;&quot;+(millisUntilFinished/1000));
}
@Override
public void onFinish() {
showExercises();
}
}.start();
}
private void showExercises() {
if(ex_id &lt; list.size())  //list size y&#39;a ts les exos
{
ex_image.setVisibility(View.VISIBLE);
btnStart.setVisibility(View.VISIBLE);
layoutGetReady.setVisibility(View.INVISIBLE);
detail_text.setVisibility(View.VISIBLE);
if (swaDB.getSettingMode() == 0)
exercisesEasyModeCountDown.start();
if (swaDB.getSettingMode() == 1)
exercisesMediumModeCountDown.start();
if (swaDB.getSettingMode() == 2)
exercisesHardModeCountDown.start();
//Set Data youno
ex_image.setImageResource(list.get(ex_id).getImage_id());
ex_name.setText(list.get(ex_id).getName());
detail_text.setText(list.get(ex_id).getDetail());
}
else
showFinished();
}
private void showFinished() {
ex_image.setVisibility(View.INVISIBLE);
btnStart.setVisibility(View.INVISIBLE);
txtCountdown.setVisibility(View.INVISIBLE);
layoutGetReady.setVisibility(View.VISIBLE);
detail_text.setVisibility(View.INVISIBLE);
progressBar.setVisibility(View.INVISIBLE);
txtGetReady.setText(&quot;FINISHED !!!&quot;);
txtCountdown.setText(&quot;F&#233;licitations ! \n Tu as fini ton entra&#238;nement ;) &quot;);
txtCountdown.setTextSize(20);
//Sauvegarder le workout de fou tavusa dans la db
swaDB.saveDay(&quot;&quot;+ Calendar.getInstance().getTimeInMillis());
}
// Countdown
CountDownTimer exercisesEasyModeCountDown = new CountDownTimer(Common.TIME_LIMIT_EASY,1000) {
@Override
public void onTick(long millisUntilFinished) {
txtTimer.setText(&quot;&quot;+1/1000);
}
@Override
public void onFinish() {
if(ex_id &lt; list.size() -1)
{
ex_id++;
progressBar.setProgress(ex_id);
txtTimer.setText(&quot;&quot;);
setExerciseInformation(ex_id);
btnStart.setText(&quot;Commencer&quot;);
}
else
{
showFinished();
}
}
};
CountDownTimer exercisesMediumModeCountDown = new CountDownTimer(Common.TIME_LIMIT_EASY,1000) {
@Override
public void onTick(long millisUntilFinished) {
txtTimer.setText(&quot;&quot;+1/1000);
}
@Override
public void onFinish() {
if(ex_id &lt; list.size() -1)
{
ex_id++;
progressBar.setProgress(ex_id);
txtTimer.setText(&quot;&quot;);
setExerciseInformation(ex_id);
btnStart.setText(&quot;Commencer&quot;);
}
else
{
showFinished();
}
}
};
CountDownTimer exercisesHardModeCountDown = new CountDownTimer(Common.TIME_LIMIT_EASY,1000) {
@Override
public void onTick(long millisUntilFinished) {
txtTimer.setText(&quot;&quot;+1/1000);
}
@Override
public void onFinish() {
if(ex_id &lt; list.size() -1)
{
ex_id++;
progressBar.setProgress(ex_id);
txtTimer.setText(&quot;&quot;);
setExerciseInformation(ex_id);
btnStart.setText(&quot;Commencer&quot;);
}
else
{
showFinished();
}
}
};
CountDownTimer restTimeCountDown = new CountDownTimer(10000,1000) {
@Override
public void onTick(long millisUntilFinished) {
txtCountdown.setText(&quot;&quot;+(millisUntilFinished/1000));
}
@Override
public void onFinish() {
setExerciseInformation(ex_id);
showExercises();
}
};
private void setExerciseInformation(int id) {
ex_image.setImageResource(list.get(id).getImage_id());
ex_name.setText(list.get(id).getName());
detail_text.setText(list.get(id).getDetail());
btnStart.setText(&quot;Commencer&quot;);
ex_image.setVisibility(View.VISIBLE);
btnStart.setVisibility(View.VISIBLE);
txtTimer.setVisibility(View.VISIBLE);
detail_text.setVisibility(View.VISIBLE);
layoutGetReady.setVisibility(View.INVISIBLE);
}
private void initData() {
list.add(new Exercise(R.drawable.test,&quot;Positionne-toi face au sol, les mains hauteur d’&#233;paules. Les jambes ne sont pas loin derri&#232;re. Rapproche tes jambes de mani&#232;re &#224; former un angle avec ton corps.\n&quot; +
&quot;Ton dos doit rester bien droit et ta t&#234;te doit &#234;tre dans le m&#234;me alignement que ton dos pendant toute l’ex&#233;cution du mouvement.\n&quot; +
&quot;Descends en PLONGEANT EN AVANT tout en restant le dos droit  puis repousse fermement pour remonter.\n&quot; ,&quot; Pompes Pike&quot;));
list.add(new Exercise(R.drawable.clappushups, &quot;Mets toi en position pompe (dos droit, bien gain&#233;, bras tendus), descends jusqu&#39;&#224; ce que tes pecs touchent le sol puis pousse de fa&#231;on explosive de sorte &#224; faire d&#233;coller ton corps loin du sol et pouvoir claquer dans tes mains.&quot;, &quot;Pompes claqu&#233;es&quot;));
list.add(new Exercise(R.drawable.dips, &quot;En appui sur les barres, buste l&#233;g&#232;rement pench&#233; vers l’avant , fl&#233;chis les bras jusqu’&#224; ce que ceux-ci se retrouvent &#224; l’horizontal , puis pousse pour revenir &#224; la position initiale.Reste toujours gain&#233;.&quot;, &quot;Dips&quot;));
list.add(new Exercise(R.drawable.diamondpushups, &quot;Mets tes mains en prise serr&#233;e ou en forme de triangle, comme sur la video ci-dessus, fais ton maximum de pompes.\n Sans prendre de repos, &#233;carte tes mains et fais ton maximum de r&#233;p&#233;titions. \n Enfin, reprends une prise basique avec tes mains et fais ton maximum de pomeps.&quot;, &quot;Superset Pompes(Diamant-Ecart&#233;es-Basiques)&quot;));
list.add(new Exercise(R.drawable.jumpsquats, &quot;Encha&#238;ne un squat avec un saut.&quot;, &quot;Squats Saut&#233;s&quot;));
}
}

My code with the for :

        if(ex_id &lt; list.size())  //list size y&#39;a ts les exos
{
for (int i = 0; i &lt; 3; i++) {
ex_image.setVisibility(View.VISIBLE);
btnStart.setVisibility(View.VISIBLE);
layoutGetReady.setVisibility(View.INVISIBLE);
detail_text.setVisibility(View.VISIBLE);
//Set Data youno
ex_image.setImageResource(list.get(ex_id).getImage_id());
ex_name.setText(list.get(ex_id).getName());
detail_text.setText(list.get(ex_id).getDetail());
showRestTime();
}
}
else
showFinished();
}

Huge thanks,
Stéphane

答案1

得分: 0

我阅读了您的要求,根据您的要求,您希望逐一显示每个集,并且重复显示它们。

您可以这样做,创建一个 CountDownTimer,为每个集设置一个时间段,然后在完成一个集后,转移到下一个集,在 setsList 达到最后一个集时,重新设置或重复定时器。

示例代码

int counter = -1;

CountDownTimer timer = null;
ArrayList<Foo> setsArrayList = null;

// foo 是通用类(添加您的集模型),setFoo 是包含单个集详细信息的对象。
void startTimer(Foo setFoo) {

    if (timer != null) {
        timer.cancel();
    }

    timer = new CountDownTimer(totalTime, setFoo.singleSetTime) {

        public void onTick(long millisUntilFinished) {
            counter++;

            updateUI(setsArrayList.get[counter]);
        }

        public void onFinish() {
            // "完成!" 或者如果您想要的话重复所有集合
            counter = 0;
            updateUI(setsArrayList.get[counter]);
        }
    }.start();
}
英文:

I read your requirements, As per your requirement you want to Show every set one by one and repeat them as well.

what you can do is create a CountDownTimer set time period to your each set then after completing one set, move to next one and when your setsList reaches to last one reset or repeat Timer.

Sample Code

  int counter=-1;
CountDownTimer timer=null;
ArrayList&lt;Foo&gt; setsArrayList=null;
// foo is generic class(add your model for sets) , and setFoo is object that contains single set details. 
void startTimer(Foo setFoo) {
if(null!=timer){
timer.cancel();
}
timer=new CountDownTimer(totalTime, setFoo.singleSetTime) {
public void onTick(long millisUntilFinished) {
counter++;
updateUI(setsArrayList.get
0
+
网站访问量
) } public void onFinish() { //&quot;done!&quot; or repeat all sets if you want to counter=0; updateUI(setsArrayList.get
0
+
网站访问量
) } }.start(); }

答案2

得分: 0

I've added a string value in my initData() which is the number of the sets for each exercise (in other words the number of times I want my showExercises() repeated) and I want to add an int and if this int value doesn't correspond to the string add int++ else just go to the other exercise
For example, the string value set_number is 3, I want to create an int(or other thing, that's just an idea) which equals to 0. After the restTimeCountdown, if the int doesn't equal to 3, int++, else continue my code
Here is the code I thinked for but it's missing the int configuration that I doesn't know how to do

The part of the startButton we need in this case with the modifications I thinked about:

else if(btnStart.getText().toString().toLowerCase().equals("fini"))
{

if(ex_id < list.size())
{
// Int configuration that I don't know how to do
int intValue = 0; // Create an integer variable
if (intValue != getSetValue("set_number")) // Recuperate the set_number value
{
showRestTime();
}
else
{
showRestTime();
ex_id++;
progressBar.setProgress(ex_id);
txtTimer.setText("");
}
}
else
showFinished();

}


the showRestTime:

private void showRestTime() {
ex_image.setVisibility(View.INVISIBLE);
btnStart.setText("passer");
btnStart.setVisibility(View.VISIBLE);
txtTimer.setVisibility(View.INVISIBLE);
detail_text.setVisibility(View.INVISIBLE);

    layoutGetReady.setVisibility(View.VISIBLE);
restTimeCountDown.start();
txtGetReady.setText("TEMPS DE REPOS");
}

the restTimeCountDown:

CountDownTimer restTimeCountDown = new CountDownTimer(10000,1000) {
@Override
public void onTick(long millisUntilFinished) {
txtCountdown.setText("" + (millisUntilFinished/1000));
}

    @Override
public void onFinish() {
setExerciseInformation(ex_id);
showExercises();
}
};

The entire code is on my post, Thanks a lot
<details>
<summary>英文:</summary>
I&#39;ve added a string value in my initData() which is the number of the sets for each exercise (in other words the number of times I want my showExercises() repeated) and I want to add an int and if this int value doesn&#39;t correspond to the string add  int++ else just go to the other exercise 
For example, the string value set_number is 3, I want to create an int(or other thing, that&#39;s just an idea) which equals to 0. After the restTimeCountdown, if the int doesn&#39;t equal to 3, int++, else continue my code 
Here is the code I thinked for but it&#39;s missing the int configuration that I doesn&#39;t know how to do 
The part of the startButton we need in this case with the modifications I thinked about: 
            else if(btnStart.getText().toString().toLowerCase().equals(&quot;fini&quot;))
{
if(ex_id &lt; list.size())
{
// Int configuration that I don&#39;t know how to do
if (int != //the set_number value we can recuperate with getSetValue but I don&#39;t know how to recuperate it in an int )
{
showRestTime();
}
else
{
showRestTime();
ex_id++;
progressBar.setProgress(ex_id);
txtTimer.setText(&quot;&quot;);
}
}
else
showFinished();
}
the showRestTime:

private void showRestTime() {
ex_image.setVisibility(View.INVISIBLE);
btnStart.setText("passer");
btnStart.setVisibility(View.VISIBLE);
txtTimer.setVisibility(View.INVISIBLE);
detail_text.setVisibility(View.INVISIBLE);

    layoutGetReady.setVisibility(View.VISIBLE);
restTimeCountDown.start();
txtGetReady.setText(&quot;TEMPS DE REPOS&quot;);
}

the restTimeCountDown: 

CountDownTimer restTimeCountDown = new CountDownTimer(10000,1000) {
@Override
public void onTick(long millisUntilFinished) {
txtCountdown.setText(""+(millisUntilFinished/1000));
}

    @Override
public void onFinish() {
setExerciseInformation(ex_id);
showExercises();
}
};
The entire code is on my post, Thanks a lot 
</details>

huangapple
  • 本文由 发表于 2020年4月10日 03:06:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/61128480.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定