英文:
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 < 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<Exercise> list = new ArrayList<>();
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("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 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");
}
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("PREPARE TOI");
new CountDownTimer(6000,1000)
{
@Override
public void onTick(long millisUntilFinished) {
txtCountdown.setText(""+(millisUntilFinished/1000));
}
@Override
public void onFinish() {
showExercises();
}
}.start();
}
private void showExercises() {
if(ex_id < list.size()) //list size y'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("FINISHED !!!");
txtCountdown.setText("Félicitations ! \n Tu as fini ton entraînement ;) ");
txtCountdown.setTextSize(20);
//Sauvegarder le workout de fou tavusa dans la db
swaDB.saveDay(""+ Calendar.getInstance().getTimeInMillis());
}
// Countdown
CountDownTimer exercisesEasyModeCountDown = new CountDownTimer(Common.TIME_LIMIT_EASY,1000) {
@Override
public void onTick(long millisUntilFinished) {
txtTimer.setText(""+1/1000);
}
@Override
public void onFinish() {
if(ex_id < list.size() -1)
{
ex_id++;
progressBar.setProgress(ex_id);
txtTimer.setText("");
setExerciseInformation(ex_id);
btnStart.setText("Commencer");
}
else
{
showFinished();
}
}
};
CountDownTimer exercisesMediumModeCountDown = new CountDownTimer(Common.TIME_LIMIT_EASY,1000) {
@Override
public void onTick(long millisUntilFinished) {
txtTimer.setText(""+1/1000);
}
@Override
public void onFinish() {
if(ex_id < list.size() -1)
{
ex_id++;
progressBar.setProgress(ex_id);
txtTimer.setText("");
setExerciseInformation(ex_id);
btnStart.setText("Commencer");
}
else
{
showFinished();
}
}
};
CountDownTimer exercisesHardModeCountDown = new CountDownTimer(Common.TIME_LIMIT_EASY,1000) {
@Override
public void onTick(long millisUntilFinished) {
txtTimer.setText(""+1/1000);
}
@Override
public void onFinish() {
if(ex_id < list.size() -1)
{
ex_id++;
progressBar.setProgress(ex_id);
txtTimer.setText("");
setExerciseInformation(ex_id);
btnStart.setText("Commencer");
}
else
{
showFinished();
}
}
};
CountDownTimer restTimeCountDown = new CountDownTimer(10000,1000) {
@Override
public void onTick(long millisUntilFinished) {
txtCountdown.setText(""+(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("Commencer");
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,"Positionne-toi face au sol, les mains hauteur d’épaules. Les jambes ne sont pas loin derrière. Rapproche tes jambes de manière à former un angle avec ton corps.\n" +
"Ton dos doit rester bien droit et ta tête doit être dans le même alignement que ton dos pendant toute l’exécution du mouvement.\n" +
"Descends en PLONGEANT EN AVANT tout en restant le dos droit puis repousse fermement pour remonter.\n" ," Pompes Pike"));
list.add(new Exercise(R.drawable.clappushups, "Mets toi en position pompe (dos droit, bien gainé, bras tendus), descends jusqu'à ce que tes pecs touchent le sol puis pousse de façon explosive de sorte à faire décoller ton corps loin du sol et pouvoir claquer dans tes mains.", "Pompes claquées"));
list.add(new Exercise(R.drawable.dips, "En appui sur les barres, buste légèrement penché vers l’avant , fléchis les bras jusqu’à ce que ceux-ci se retrouvent à l’horizontal , puis pousse pour revenir à la position initiale.Reste toujours gainé.", "Dips"));
list.add(new Exercise(R.drawable.diamondpushups, "Mets tes mains en prise serrée ou en forme de triangle, comme sur la video ci-dessus, fais ton maximum de pompes.\n Sans prendre de repos, écarte tes mains et fais ton maximum de répétitions. \n Enfin, reprends une prise basique avec tes mains et fais ton maximum de pomeps.", "Superset Pompes(Diamant-Ecartées-Basiques)"));
list.add(new Exercise(R.drawable.jumpsquats, "Enchaîne un squat avec un saut.", "Squats Sautés"));
}
}
My code with the for :
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);
//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<Foo> 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.get0+网站访问量)
}
public void onFinish() {
//"done!" or repeat all sets if you want to
counter=0;
updateUI(setsArrayList.get0+网站访问量)
}
}.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'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
if (int != //the set_number value we can recuperate with getSetValue but I don't know how to recuperate it in an int )
{
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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论