Bonjour,

je viens de développer une petite application Android (un petit programme de musculation pour la gymnastique artistique). Je remarque en programmant mon application que les écrans se ressemblent, seul changent les images et le texte d'explication, la durée de l'exercice, ...

Comment améliorer cette application? Si il y a répétition de code, il y a surement moyen d'améliorer... Mais comment...

Je vous mets le code d'un layout et de l'activity pour que, peut-être, vous me donniez des idées.

Voici le layout

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
 
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/LinearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:weightSum="1" >
 
        <TextView
            android:id="@+id/textView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/title_activity_jambes_screen1"
            android:textStyle="bold" />
 
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center" >
 
            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/jambes1a" />
 
            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/jambes1b" />
        </LinearLayout>
 
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Durée : 1 minute d&apos;activité + 1 minute de repos." />
 
        <TextView
            android:id="@+id/textView7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Position : Jambes serrées." />
 
        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Plier les jambes jusqu&apos;à la position accroupie." />
 
        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Maintenir la position 2 secondes pour étirer les muscles." />
 
        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/se_redresser_" />
 
        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Répéter ce mouvement pendant 1 minute." />
 
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="right" >
 
            <Button
                android:id="@+id/btnGo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/go_" />
 
            <Button
                android:id="@+id/btnStop"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/stop" />
 
            <Button
                android:id="@+id/btnSuivant"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/suivant" />
        </LinearLayout>
 
        <TextView
            android:id="@+id/tvEtat1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="TextView" />
 
        <TextView
            android:id="@+id/tvEtat2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="TextView" />
 
 
    </LinearLayout>
 
</ScrollView>
Voici L'activity

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
 
package com.miniil.gymmuscu;
 
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
 
public class JambesScreen1 extends Activity {
	TextView etat1;
	TextView etat2;
	Button go;
	Button stop;
	Button suivant;
	MediaPlayer bip;
	int tpsPreparation = 10;
	TimerPrepare myTimerPrepare;
	TimerActivite myTimerActivite;
	TimerRepos myTimerRepos;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jambes_screen1);        
 
        etat1 = (TextView)findViewById(R.id.tvEtat1);
        etat2 = (TextView)findViewById(R.id.tvEtat2);
        etat1.setText("");
        etat2.setText("");
 
        go = (Button) findViewById(R.id.btnGo);
        stop = (Button) findViewById(R.id.btnStop);
        suivant = (Button) findViewById(R.id.btnSuivant);
 
        bip = MediaPlayer.create(this, R.raw.bip);
 
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        tpsPreparation = Integer.decode(preferences.getString("TPSPREPA", "10"));
        tpsPreparation = tpsPreparation * 1000;
 
        go.setOnClickListener(new View.OnClickListener() {			
			public void onClick(View v) {
				etat1.setText("Préparer-vous");
				myTimerPrepare = new TimerPrepare(tpsPreparation, 1000);
				bip.start();
			    myTimerPrepare.start();
			}
		});
 
        stop.setOnClickListener(new View.OnClickListener() {			
			public void onClick(View v) {			
				etat1.setText("");
				etat2.setText("");
				if (myTimerPrepare != null) myTimerPrepare.cancel();
				if (myTimerActivite != null) myTimerActivite.cancel();
				if (myTimerRepos != null) myTimerRepos.cancel();				
			}
		});
 
        suivant.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), JambesScreen2.class);
                startActivityForResult(myIntent, 0);
            }
 
        }); 
 
    }
 
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_jambes_screen1, menu);
        return true;
    }
 
    //Preparation
    public class TimerPrepare extends CountDownTimer {    	
    	public TimerPrepare(long millisInFuture, long countDownInterval) {
    		super(millisInFuture, countDownInterval);
    	}
 
    	@Override
    	public void onFinish() {
    		etat1.setText("Activité!");
    		myTimerActivite = new TimerActivite(60000,1000);
    		bip.start();
		    myTimerActivite.start();
    	}
 
    	@Override
    	public void onTick(long millisUntilFinished) {
    		etat2.setText("Left: " + millisUntilFinished/1000);
   		}
 
    }
 
    //Activite
    public class TimerActivite extends CountDownTimer {
    	public TimerActivite(long millisInFutur, long countDownInterval) {
    		super(millisInFutur, countDownInterval);
    	}
 
    	@Override
    	public void onFinish(){
    		etat1.setText("Repos!");
    		myTimerRepos = new TimerRepos(60000,1000);
    		bip.start();
		    myTimerRepos.start();
    	}
 
    	@Override
    	public void onTick(long millisUntilFinished){
    		etat2.setText("Left: " + millisUntilFinished/1000);
    	}
    }
 
    //Repos
    public class TimerRepos extends CountDownTimer {
    	public TimerRepos(long millisInFutur, long countDownInterval) {
    		super(millisInFutur, countDownInterval);
    	}
 
    	@Override
    	public void onFinish(){
    		bip.start();
    		etat1.setText("Terminé! Cliquez sur Suivant");
    	}
 
    	@Override
    	public void onTick(long millisUntilFinished){
    		etat2.setText("Left: " + millisUntilFinished/1000);
    	}
    }
}
D'avance merci pour votre aide.

Bonne soirée