c8059613
JLo'w
Re-fonte de l'app...
|
1
2
|
package com.example.app_10p5;
|
e9b6c14d
JLo'w
Passage au suppor...
|
3
|
import android.app.Activity;
|
3c5d3089
JLo'w
Work in progress ...
|
4
5
|
import android.app.FragmentManager;
import android.app.FragmentTransaction;
|
2681581a
JLo'w
menu pour changer...
|
6
|
import android.content.Context;
|
c8059613
JLo'w
Re-fonte de l'app...
|
7
|
import android.content.Intent;
|
2681581a
JLo'w
menu pour changer...
|
8
|
import android.graphics.drawable.BitmapDrawable;
|
0aec73b6
JLo'w
Petit changement ...
|
9
|
import android.graphics.drawable.ColorDrawable;
|
c8059613
JLo'w
Re-fonte de l'app...
|
10
|
import android.os.Bundle;
|
c8059613
JLo'w
Re-fonte de l'app...
|
11
|
import android.support.v4.view.ViewPager;
|
2681581a
JLo'w
menu pour changer...
|
12
13
|
import android.view.Gravity;
import android.view.LayoutInflater;
|
0aec73b6
JLo'w
Petit changement ...
|
14
15
16
|
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
|
c8059613
JLo'w
Re-fonte de l'app...
|
17
|
import android.view.View;
|
2681581a
JLo'w
menu pour changer...
|
18
19
|
import android.view.ViewGroup;
import android.widget.Button;
|
520cecde
JLo'w
Un petit plus, un...
|
20
|
import android.widget.EditText;
|
2681581a
JLo'w
menu pour changer...
|
21
22
23
24
|
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.PopupWindow;
|
93f90e35
JLo'w
NFC et foreground
|
25
26
|
import android.widget.Toast;
|
c1f92981
JLo'w
Implémentation de...
|
27
28
29
30
31
|
import org.json.JSONObject;
import java.net.URL;
import java.util.HashMap;
|
c8059613
JLo'w
Re-fonte de l'app...
|
32
33
34
35
|
/**
* Created by beaus on 24/04/2016.
*/
|
3c5d3089
JLo'w
Work in progress ...
|
36
|
public class MainActivite extends Activity implements ASyncResponse, main_tab_frag.OnFragmentInteractionListener {
|
c8059613
JLo'w
Re-fonte de l'app...
|
37
|
|
520cecde
JLo'w
Un petit plus, un...
|
38
39
40
41
42
43
44
45
46
47
|
public static final int STATE_RIEN = 0;
public static final int STATE_COMMANDE = 3;
public static final int STATE_VIDANGE = 4;
public static final int STATE_RECHARGEMENT = 2;
public static final int STATE_CREATION_COMPTE = 1;
public static final int STATE_CONNEXION = 5;
public static final long EXPIRATION = 1000*60*10;
private int mState;
private String mToken;
|
8cd8911a
JLo'w
Connexion enfin f...
|
48
|
private int mDroit;
|
520cecde
JLo'w
Un petit plus, un...
|
49
|
private long mTimeToken;
|
8cd8911a
JLo'w
Connexion enfin f...
|
50
|
private String mUser;
|
520cecde
JLo'w
Un petit plus, un...
|
51
|
|
c8059613
JLo'w
Re-fonte de l'app...
|
52
53
54
55
|
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);
|
520cecde
JLo'w
Un petit plus, un...
|
56
57
58
59
60
|
mState = STATE_RIEN;
mTimeToken = -1;
mToken = "";
|
0aec73b6
JLo'w
Petit changement ...
|
61
62
|
getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary)));
|
2681581a
JLo'w
menu pour changer...
|
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
if(savedInstanceState == null){
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
main_tab_frag fragment = new main_tab_frag();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();
}
else{
mTimeToken = savedInstanceState.getLong("timeToken");
mToken = savedInstanceState.getString("token");
mState = savedInstanceState.getInt("state");
mUser = savedInstanceState.getString("user");
mDroit = savedInstanceState.getInt("droit");
}
|
c8059613
JLo'w
Re-fonte de l'app...
|
77
78
|
}
|
c66109e1
JLo'w
Ajout du code des...
|
79
|
@Override
|
0aec73b6
JLo'w
Petit changement ...
|
80
81
82
83
84
85
86
87
88
|
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
|
2681581a
JLo'w
menu pour changer...
|
89
90
91
92
93
94
95
96
97
98
|
if(item.getItemId() == R.id.menu_2_choice_1){
CarteActivite.HOST = "https://10p5.clubinfo.frogeye.fr/";
item.setChecked(true);
}
else if(item.getItemId() == R.id.menu_2_choice_2){
CarteActivite.HOST = "http://pcbar.insecure.deule.net/";
item.setChecked(true);
}
return super.onOptionsItemSelected(item);
|
0aec73b6
JLo'w
Petit changement ...
|
99
100
101
|
}
@Override
|
3c5d3089
JLo'w
Work in progress ...
|
102
103
104
105
106
|
public void onFragmentInteraction(String s){
}
@Override
|
c66109e1
JLo'w
Ajout du code des...
|
107
108
109
110
111
112
113
114
115
116
|
public void onSaveInstanceState(Bundle savedInstanceState){
savedInstanceState.putString("token", mToken);
savedInstanceState.putInt("state", mState);
savedInstanceState.putString("user", mUser);
savedInstanceState.putInt("droit", mDroit);
savedInstanceState.putLong("timeToken", mTimeToken);
super.onSaveInstanceState(savedInstanceState);
}
|
c66109e1
JLo'w
Ajout du code des...
|
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
|
public void valideCreationCompte(View v){
if((mToken != "") && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) {
EditText champMontant = (EditText) findViewById(R.id.creation_montant);
float montant = 0.0f;
try{
montant = Float.parseFloat(champMontant.getText().toString());
}
catch (Throwable t){
Toast.makeText(this, "Remplir le champ montant avec un nombre: " + t.toString(), Toast.LENGTH_LONG).show();
}
if((montant > 0.0f) && (montant < 200.0f) && (mDroit >= 1)){
mState = STATE_CREATION_COMPTE;
Intent intent = new Intent(this, CarteActivite.class);
intent.putExtra("token", mToken);
intent.putExtra("state", mState);
intent.putExtra("montant", montant);
startActivityForResult(intent, mState);
}
else{
Toast.makeText(this, "Valeur incorrecte ou droit insuffisant.", Toast.LENGTH_LONG).show();
}
}
else{
Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show();
|
2681581a
JLo'w
menu pour changer...
|
143
144
|
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setCurrentItem(0);
|
c66109e1
JLo'w
Ajout du code des...
|
145
146
147
|
}
}
|
c8059613
JLo'w
Re-fonte de l'app...
|
148
149
|
public void valideCommande(View v)
{
|
520cecde
JLo'w
Un petit plus, un...
|
150
151
152
|
if((mToken != "") && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) {
EditText champMontant = (EditText) findViewById(R.id.commande_prix);
EditText champQuantite = (EditText) findViewById(R.id.commande_quantite);
|
c66109e1
JLo'w
Ajout du code des...
|
153
154
155
156
157
158
159
160
161
162
163
|
float montant = 0.0f;
int quantite = 0;
try{
montant = Float.parseFloat(champMontant.getText().toString());
quantite = Integer.parseInt(champQuantite.getText().toString());
}
catch (Throwable t)
{
Toast.makeText(this, "Remplir les champs avec des nombres: " + t.toString(), Toast.LENGTH_LONG).show();
}
|
520cecde
JLo'w
Un petit plus, un...
|
164
|
|
c66109e1
JLo'w
Ajout du code des...
|
165
|
if ((montant > 0.0f) && (montant < 200.0f) && (quantite > 0) && (mDroit >= 1)) {
|
520cecde
JLo'w
Un petit plus, un...
|
166
167
168
169
170
171
172
173
|
mState = STATE_COMMANDE;
Intent intent = new Intent(this, CarteActivite.class);
intent.putExtra("token", mToken);
intent.putExtra("state", mState);
intent.putExtra("montant", montant);
intent.putExtra("quantite", quantite);
startActivityForResult(intent, mState);
}
|
c66109e1
JLo'w
Ajout du code des...
|
174
175
176
|
else{
Toast.makeText(this, "Valeur incorrecte ou droit insuffisant.", Toast.LENGTH_LONG).show();
}
|
520cecde
JLo'w
Un petit plus, un...
|
177
178
179
|
}
else{
Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show();
|
2681581a
JLo'w
menu pour changer...
|
180
181
|
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setCurrentItem(0);
|
520cecde
JLo'w
Un petit plus, un...
|
182
183
184
185
186
|
}
}
public void valideRechargement(View v)
{
|
96cf88d2
JLo'w
Réception de JSON...
|
187
|
if((mToken != "") && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) {
|
c66109e1
JLo'w
Ajout du code des...
|
188
189
190
191
192
193
194
195
196
|
EditText champMontant = (EditText) findViewById(R.id.rechargement_champ_montant);
float montant = 0.0f;
try{
montant = Float.parseFloat(champMontant.getText().toString());
}
catch (Throwable t){
Toast.makeText(this, "Remplir le champ montant avec un nombre: " + t.toString(), Toast.LENGTH_LONG).show();
}
|
520cecde
JLo'w
Un petit plus, un...
|
197
|
|
c66109e1
JLo'w
Ajout du code des...
|
198
199
200
201
202
203
204
205
206
207
208
|
if((montant > 0.0f) && (montant < 200.0f) && (mDroit >= 2)){
mState = STATE_RECHARGEMENT;
Intent intent = new Intent(this, CarteActivite.class);
intent.putExtra("token", mToken);
intent.putExtra("state", mState);
intent.putExtra("montant", montant);
startActivityForResult(intent, mState);
}
else{
Toast.makeText(this, "Valeur incorrecte ou droit insuffisant.", Toast.LENGTH_LONG).show();
}
|
520cecde
JLo'w
Un petit plus, un...
|
209
210
211
|
}
else{
Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show();
|
2681581a
JLo'w
menu pour changer...
|
212
213
|
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setCurrentItem(0);
|
520cecde
JLo'w
Un petit plus, un...
|
214
215
216
217
218
219
220
221
|
}
}
public void valideConnection(View v)
{
EditText viewUser = (EditText) findViewById(R.id.connection_username);
EditText viewPsw = (EditText) findViewById(R.id.connection_password);
|
c1f92981
JLo'w
Implémentation de...
|
222
223
224
|
String user = viewUser.getText().toString();
String password = viewPsw.getText().toString();
|
520cecde
JLo'w
Un petit plus, un...
|
225
226
|
if ((user != "") && (password != "")) {
mState = STATE_CONNEXION;
|
c1f92981
JLo'w
Implémentation de...
|
227
228
|
try{
|
c1f92981
JLo'w
Implémentation de...
|
229
|
URL url = new URL(CarteActivite.HOST + "api/utilisateur/connexion");
|
c1f92981
JLo'w
Implémentation de...
|
230
231
232
233
234
235
236
237
|
HashMap<String, String> param = new HashMap<String, String>();
param.put("login", user);
param.put("mdp", password);
NetworkThread nt = new NetworkThread(url, param);
nt.delegate = this;
nt.execute();
}
catch (Throwable t) {
|
2681581a
JLo'w
menu pour changer...
|
238
|
System.out.println("Exception: " + t.toString());
|
c1f92981
JLo'w
Implémentation de...
|
239
|
}
|
520cecde
JLo'w
Un petit plus, un...
|
240
|
}
|
c66109e1
JLo'w
Ajout du code des...
|
241
242
243
|
else{
Toast.makeText(this, "Veuillez remplir les champs.", Toast.LENGTH_LONG).show();
}
|
520cecde
JLo'w
Un petit plus, un...
|
244
|
}
|
8d573e63
JLo'w
Mise en place de ...
|
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
public void valideVidange(View v){
if((mToken != "") && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) {
if((mDroit >= 2)){
mState = STATE_VIDANGE;
Intent intent = new Intent(this, CarteActivite.class);
intent.putExtra("token", mToken);
intent.putExtra("state", mState);
startActivityForResult(intent, mState);
}
else{
Toast.makeText(this, "Droit insuffisant.", Toast.LENGTH_LONG).show();
}
}
else{
Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show();
|
2681581a
JLo'w
menu pour changer...
|
262
263
|
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setCurrentItem(0);
|
8d573e63
JLo'w
Mise en place de ...
|
264
265
|
}
}
|
520cecde
JLo'w
Un petit plus, un...
|
266
267
268
269
|
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
//TODO: faire des choses avec ca
|
4ef24041
JLo'w
Retour du JSONObj...
|
270
271
272
273
274
275
276
|
try{
JSONObject json = new JSONObject(data.getStringExtra("json"));
Toast.makeText(this, "Status: " + json.getString("status"), Toast.LENGTH_SHORT).show();
}
catch (Throwable t){
|
2681581a
JLo'w
menu pour changer...
|
277
|
Toast.makeText(this, "Retour", Toast.LENGTH_SHORT).show();
|
4ef24041
JLo'w
Retour du JSONObj...
|
278
279
280
|
}
|
520cecde
JLo'w
Un petit plus, un...
|
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
switch (requestCode) {
case STATE_COMMANDE:
break;
case STATE_CONNEXION:
break;
case STATE_CREATION_COMPTE:
break;
case STATE_RECHARGEMENT:
break;
case STATE_VIDANGE:
break;
case STATE_RIEN:
default:
Toast.makeText(this, "WTF, le cancer est dans l'application!!", Toast.LENGTH_LONG).show();
break;
}
|
c8059613
JLo'w
Re-fonte de l'app...
|
297
|
}
|
93f90e35
JLo'w
NFC et foreground
|
298
|
|
c1f92981
JLo'w
Implémentation de...
|
299
300
301
|
/* Retour du network thread */
@Override
public void processFinish(JSONObject output) {
|
96cf88d2
JLo'w
Réception de JSON...
|
302
303
|
if(output.length() != 0){
try{
|
8cd8911a
JLo'w
Connexion enfin f...
|
304
305
|
if(output.get("status").toString().equals("ok")){
mToken = output.get("jeton").toString();
|
96cf88d2
JLo'w
Réception de JSON...
|
306
|
mTimeToken = System.currentTimeMillis();
|
8cd8911a
JLo'w
Connexion enfin f...
|
307
308
309
|
mDroit = output.getInt("droit");
mUser = output.get("login").toString();
Toast.makeText(this, "Bonjour " + mUser + " vous êtes bien connecté pour " + EXPIRATION / (1000 * 60) + " minutes.", Toast.LENGTH_LONG).show();
|
ecd8a267
JLo'w
Petites correctio...
|
310
311
|
EditText coUser = (EditText) findViewById(R.id.connection_password);
coUser.setText("");
|
2681581a
JLo'w
menu pour changer...
|
312
313
|
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setCurrentItem(1);
|
96cf88d2
JLo'w
Réception de JSON...
|
314
315
316
317
318
319
|
}
else{
Toast.makeText(this, "Erreur dans la requête: " + output.get("status"), Toast.LENGTH_LONG).show();
}
}
catch(Throwable t){
|
8cd8911a
JLo'w
Connexion enfin f...
|
320
|
Toast.makeText(this, "WTF, le cancer est dans l'application!!" + t.toString(), Toast.LENGTH_LONG).show();
|
96cf88d2
JLo'w
Réception de JSON...
|
321
322
323
324
325
|
}
}
else{
Toast.makeText(this, "Impossible de se connecter au serveur", Toast.LENGTH_LONG).show();
}
|
c1f92981
JLo'w
Implémentation de...
|
326
|
}
|
3c5d3089
JLo'w
Work in progress ...
|
327
328
329
330
331
332
333
334
|
public String getToken(){
return mToken;
}
public long getTimeToken(){
return mTimeToken;
}
|
2681581a
JLo'w
menu pour changer...
|
335
336
337
338
339
340
341
|
public void settingsPopup(View v) {
PopupMenu popup = new PopupMenu(this, v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.popup_settings, popup.getMenu());
popup.show();
}
|
c8059613
JLo'w
Re-fonte de l'app...
|
342
|
}
|