Commit c66109e1fb8d5fc9ca719d71bcaba54d81b11d5f
1 parent
d57b6aad
Ajout du code des fonctions onclick et controles
Showing
1 changed file
with
94 additions
and
6 deletions
Show diff stats
PremiereActivite/app/src/main/java/com/example/app_10p5/MainActivite.java
@@ -67,7 +67,7 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { | @@ -67,7 +67,7 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { | ||
67 | else{ | 67 | else{ |
68 | viewPager.setCurrentItem(tab.getPosition()); //Empeche un bug graphique | 68 | viewPager.setCurrentItem(tab.getPosition()); //Empeche un bug graphique |
69 | viewPager.setCurrentItem(0); | 69 | viewPager.setCurrentItem(0); |
70 | - Toast.makeText(MainActivite.this, "Veuillez vous connecter.", Toast.LENGTH_LONG).show(); | 70 | + Toast.makeText(MainActivite.this, "Veuillez vous connecter biatche.", Toast.LENGTH_LONG).show(); |
71 | } | 71 | } |
72 | } | 72 | } |
73 | 73 | ||
@@ -83,15 +83,77 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { | @@ -83,15 +83,77 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { | ||
83 | }); | 83 | }); |
84 | } | 84 | } |
85 | 85 | ||
86 | + @Override | ||
87 | + public void onSaveInstanceState(Bundle savedInstanceState){ | ||
88 | + savedInstanceState.putString("token", mToken); | ||
89 | + savedInstanceState.putInt("state", mState); | ||
90 | + savedInstanceState.putString("user", mUser); | ||
91 | + savedInstanceState.putInt("droit", mDroit); | ||
92 | + savedInstanceState.putLong("timeToken", mTimeToken); | ||
93 | + | ||
94 | + super.onSaveInstanceState(savedInstanceState); | ||
95 | + } | ||
96 | + | ||
97 | + @Override | ||
98 | + public void onRestoreInstanceState(Bundle savedInstanceState) { | ||
99 | + mTimeToken = savedInstanceState.getLong("timeToken"); | ||
100 | + mToken = savedInstanceState.getString("user"); | ||
101 | + mState = savedInstanceState.getInt("state"); | ||
102 | + mUser = savedInstanceState.getString("user"); | ||
103 | + mDroit = savedInstanceState.getInt("droit"); | ||
104 | + | ||
105 | + super.onRestoreInstanceState(savedInstanceState); | ||
106 | + } | ||
107 | + | ||
108 | + public void valideCreationCompte(View v){ | ||
109 | + if((mToken != "") && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) { | ||
110 | + EditText champMontant = (EditText) findViewById(R.id.creation_montant); | ||
111 | + float montant = 0.0f; | ||
112 | + | ||
113 | + try{ | ||
114 | + montant = Float.parseFloat(champMontant.getText().toString()); | ||
115 | + } | ||
116 | + catch (Throwable t){ | ||
117 | + Toast.makeText(this, "Remplir le champ montant avec un nombre: " + t.toString(), Toast.LENGTH_LONG).show(); | ||
118 | + } | ||
119 | + | ||
120 | + if((montant > 0.0f) && (montant < 200.0f) && (mDroit >= 1)){ | ||
121 | + mState = STATE_CREATION_COMPTE; | ||
122 | + Intent intent = new Intent(this, CarteActivite.class); | ||
123 | + intent.putExtra("token", mToken); | ||
124 | + intent.putExtra("state", mState); | ||
125 | + intent.putExtra("montant", montant); | ||
126 | + startActivityForResult(intent, mState); | ||
127 | + } | ||
128 | + else{ | ||
129 | + Toast.makeText(this, "Valeur incorrecte ou droit insuffisant.", Toast.LENGTH_LONG).show(); | ||
130 | + } | ||
131 | + } | ||
132 | + else{ | ||
133 | + Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show(); | ||
134 | + final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); | ||
135 | + viewPager.setCurrentItem(0); | ||
136 | + } | ||
137 | + } | ||
138 | + | ||
86 | public void valideCommande(View v) | 139 | public void valideCommande(View v) |
87 | { | 140 | { |
88 | if((mToken != "") && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) { | 141 | if((mToken != "") && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) { |
89 | EditText champMontant = (EditText) findViewById(R.id.commande_prix); | 142 | EditText champMontant = (EditText) findViewById(R.id.commande_prix); |
90 | EditText champQuantite = (EditText) findViewById(R.id.commande_quantite); | 143 | EditText champQuantite = (EditText) findViewById(R.id.commande_quantite); |
91 | - float montant = Float.parseFloat(champMontant.getText().toString()); | ||
92 | - int quantite = Integer.parseInt(champQuantite.getText().toString()); | 144 | + float montant = 0.0f; |
145 | + int quantite = 0; | ||
146 | + | ||
147 | + try{ | ||
148 | + montant = Float.parseFloat(champMontant.getText().toString()); | ||
149 | + quantite = Integer.parseInt(champQuantite.getText().toString()); | ||
150 | + } | ||
151 | + catch (Throwable t) | ||
152 | + { | ||
153 | + Toast.makeText(this, "Remplir les champs avec des nombres: " + t.toString(), Toast.LENGTH_LONG).show(); | ||
154 | + } | ||
93 | 155 | ||
94 | - if ((montant > 0.0) && (montant < 200.0)) { | 156 | + if ((montant > 0.0f) && (montant < 200.0f) && (quantite > 0) && (mDroit >= 1)) { |
95 | mState = STATE_COMMANDE; | 157 | mState = STATE_COMMANDE; |
96 | Intent intent = new Intent(this, CarteActivite.class); | 158 | Intent intent = new Intent(this, CarteActivite.class); |
97 | intent.putExtra("token", mToken); | 159 | intent.putExtra("token", mToken); |
@@ -100,6 +162,9 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { | @@ -100,6 +162,9 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { | ||
100 | intent.putExtra("quantite", quantite); | 162 | intent.putExtra("quantite", quantite); |
101 | startActivityForResult(intent, mState); | 163 | startActivityForResult(intent, mState); |
102 | } | 164 | } |
165 | + else{ | ||
166 | + Toast.makeText(this, "Valeur incorrecte ou droit insuffisant.", Toast.LENGTH_LONG).show(); | ||
167 | + } | ||
103 | } | 168 | } |
104 | else{ | 169 | else{ |
105 | Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show(); | 170 | Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show(); |
@@ -111,7 +176,27 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { | @@ -111,7 +176,27 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { | ||
111 | public void valideRechargement(View v) | 176 | public void valideRechargement(View v) |
112 | { | 177 | { |
113 | if((mToken != "") && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) { | 178 | if((mToken != "") && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) { |
179 | + EditText champMontant = (EditText) findViewById(R.id.rechargement_champ_montant); | ||
180 | + float montant = 0.0f; | ||
181 | + | ||
182 | + try{ | ||
183 | + montant = Float.parseFloat(champMontant.getText().toString()); | ||
184 | + } | ||
185 | + catch (Throwable t){ | ||
186 | + Toast.makeText(this, "Remplir le champ montant avec un nombre: " + t.toString(), Toast.LENGTH_LONG).show(); | ||
187 | + } | ||
114 | 188 | ||
189 | + if((montant > 0.0f) && (montant < 200.0f) && (mDroit >= 2)){ | ||
190 | + mState = STATE_RECHARGEMENT; | ||
191 | + Intent intent = new Intent(this, CarteActivite.class); | ||
192 | + intent.putExtra("token", mToken); | ||
193 | + intent.putExtra("state", mState); | ||
194 | + intent.putExtra("montant", montant); | ||
195 | + startActivityForResult(intent, mState); | ||
196 | + } | ||
197 | + else{ | ||
198 | + Toast.makeText(this, "Valeur incorrecte ou droit insuffisant.", Toast.LENGTH_LONG).show(); | ||
199 | + } | ||
115 | } | 200 | } |
116 | else{ | 201 | else{ |
117 | Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show(); | 202 | Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show(); |
@@ -128,8 +213,6 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { | @@ -128,8 +213,6 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { | ||
128 | String user = viewUser.getText().toString(); | 213 | String user = viewUser.getText().toString(); |
129 | String password = viewPsw.getText().toString(); | 214 | String password = viewPsw.getText().toString(); |
130 | 215 | ||
131 | - System.out.println(user + " " + password); | ||
132 | - | ||
133 | if ((user != "") && (password != "")) { | 216 | if ((user != "") && (password != "")) { |
134 | mState = STATE_CONNEXION; | 217 | mState = STATE_CONNEXION; |
135 | 218 | ||
@@ -148,6 +231,9 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { | @@ -148,6 +231,9 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { | ||
148 | //TODO: gérer les exceptions du cancer de la connexion | 231 | //TODO: gérer les exceptions du cancer de la connexion |
149 | } | 232 | } |
150 | } | 233 | } |
234 | + else{ | ||
235 | + Toast.makeText(this, "Veuillez remplir les champs.", Toast.LENGTH_LONG).show(); | ||
236 | + } | ||
151 | } | 237 | } |
152 | 238 | ||
153 | @Override | 239 | @Override |
@@ -182,6 +268,8 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { | @@ -182,6 +268,8 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { | ||
182 | mDroit = output.getInt("droit"); | 268 | mDroit = output.getInt("droit"); |
183 | mUser = output.get("login").toString(); | 269 | mUser = output.get("login").toString(); |
184 | Toast.makeText(this, "Bonjour " + mUser + " vous êtes bien connecté pour " + EXPIRATION / (1000 * 60) + " minutes.", Toast.LENGTH_LONG).show(); | 270 | Toast.makeText(this, "Bonjour " + mUser + " vous êtes bien connecté pour " + EXPIRATION / (1000 * 60) + " minutes.", Toast.LENGTH_LONG).show(); |
271 | + final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); | ||
272 | + viewPager.setCurrentItem(1); | ||
185 | } | 273 | } |
186 | else{ | 274 | else{ |
187 | Toast.makeText(this, "Erreur dans la requête: " + output.get("status"), Toast.LENGTH_LONG).show(); | 275 | Toast.makeText(this, "Erreur dans la requête: " + output.get("status"), Toast.LENGTH_LONG).show(); |