Commit c1f929811bfab50f5cbd07cf37b31c7c4e2bd43a
1 parent
2e3c9847
Implémentation de la connexion
Showing
1 changed file
with
30 additions
and
8 deletions
Show diff stats
PremiereActivite/app/src/main/java/com/example/app_10p5/MainActivite.java
... | ... | @@ -9,11 +9,16 @@ import android.view.View; |
9 | 9 | import android.widget.EditText; |
10 | 10 | import android.widget.Toast; |
11 | 11 | |
12 | +import org.json.JSONObject; | |
13 | + | |
14 | +import java.net.URL; | |
15 | +import java.util.HashMap; | |
16 | + | |
12 | 17 | |
13 | 18 | /** |
14 | 19 | * Created by beaus on 24/04/2016. |
15 | 20 | */ |
16 | -public class MainActivite extends FragmentActivity { | |
21 | +public class MainActivite extends FragmentActivity implements ASyncResponse { | |
17 | 22 | |
18 | 23 | public static final int STATE_RIEN = 0; |
19 | 24 | public static final int STATE_COMMANDE = 3; |
... | ... | @@ -117,16 +122,28 @@ public class MainActivite extends FragmentActivity { |
117 | 122 | EditText viewUser = (EditText) findViewById(R.id.connection_username); |
118 | 123 | EditText viewPsw = (EditText) findViewById(R.id.connection_password); |
119 | 124 | |
120 | - String user = viewUser.toString(); | |
121 | - String password = viewPsw.toString(); | |
125 | + String user = viewUser.getText().toString(); | |
126 | + String password = viewPsw.getText().toString(); | |
127 | + | |
128 | + System.out.println(user + " " + password); | |
122 | 129 | |
123 | 130 | if ((user != "") && (password != "")) { |
124 | 131 | mState = STATE_CONNEXION; |
125 | - Intent intent = new Intent(this, CarteActivite.class); | |
126 | - intent.putExtra("user", user); | |
127 | - intent.putExtra("state", mState); | |
128 | - intent.putExtra("password", password); | |
129 | - startActivityForResult(intent, mState); | |
132 | + | |
133 | + try{ | |
134 | + System.out.println("try"); | |
135 | + URL url = new URL(CarteActivite.HOST + "api/utilisateur/connexion"); | |
136 | + System.out.println("url"); | |
137 | + HashMap<String, String> param = new HashMap<String, String>(); | |
138 | + param.put("login", user); | |
139 | + param.put("mdp", password); | |
140 | + NetworkThread nt = new NetworkThread(url, param); | |
141 | + nt.delegate = this; | |
142 | + nt.execute(); | |
143 | + } | |
144 | + catch (Throwable t) { | |
145 | + //TODO: gérer les exceptions du cancer de la connexion | |
146 | + } | |
130 | 147 | } |
131 | 148 | } |
132 | 149 | |
... | ... | @@ -151,4 +168,9 @@ public class MainActivite extends FragmentActivity { |
151 | 168 | } |
152 | 169 | } |
153 | 170 | |
171 | + /* Retour du network thread */ | |
172 | + @Override | |
173 | + public void processFinish(JSONObject output) { | |
174 | + //TODO: Uniquement pour la connexion | |
175 | + } | |
154 | 176 | } | ... | ... |