Commit 2681581ae8ca82850f56246f3769598fc2f7701a
1 parent
3c5d3089
menu pour changer de serveur + restauration avant
Showing
3 changed files
with
64 additions
and
33 deletions
Show diff stats
PremiereActivite/app/src/main/java/com/example/app_10p5/CarteActivite.java
@@ -3,6 +3,7 @@ package com.example.app_10p5; | @@ -3,6 +3,7 @@ package com.example.app_10p5; | ||
3 | import android.app.Activity; | 3 | import android.app.Activity; |
4 | import android.app.PendingIntent; | 4 | import android.app.PendingIntent; |
5 | import android.content.Intent; | 5 | import android.content.Intent; |
6 | +import android.graphics.drawable.ColorDrawable; | ||
6 | import android.nfc.NfcAdapter; | 7 | import android.nfc.NfcAdapter; |
7 | import android.nfc.Tag; | 8 | import android.nfc.Tag; |
8 | import android.nfc.tech.MifareClassic; | 9 | import android.nfc.tech.MifareClassic; |
@@ -23,12 +24,13 @@ public class CarteActivite extends Activity implements ASyncResponse { | @@ -23,12 +24,13 @@ public class CarteActivite extends Activity implements ASyncResponse { | ||
23 | private HashMap<String, String> mParam; | 24 | private HashMap<String, String> mParam; |
24 | private String mAPI; | 25 | private String mAPI; |
25 | 26 | ||
26 | - public static final String HOST = "https://10p5.clubinfo.frogeye.fr/"; | 27 | + public static String HOST = "https://10p5.clubinfo.frogeye.fr/"; |
27 | 28 | ||
28 | @Override | 29 | @Override |
29 | protected void onCreate(Bundle savedInstanceState) { | 30 | protected void onCreate(Bundle savedInstanceState) { |
30 | super.onCreate(savedInstanceState); | 31 | super.onCreate(savedInstanceState); |
31 | setContentView(R.layout.layout_carte); | 32 | setContentView(R.layout.layout_carte); |
33 | + getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary))); | ||
32 | 34 | ||
33 | mParam = new HashMap<String, String>(); | 35 | mParam = new HashMap<String, String>(); |
34 | 36 | ||
@@ -180,7 +182,6 @@ public class CarteActivite extends Activity implements ASyncResponse { | @@ -180,7 +182,6 @@ public class CarteActivite extends Activity implements ASyncResponse { | ||
180 | 182 | ||
181 | public void clientAPI() { | 183 | public void clientAPI() { |
182 | try { | 184 | try { |
183 | - System.out.println("chatte"); | ||
184 | URL url = new URL(HOST + mAPI); | 185 | URL url = new URL(HOST + mAPI); |
185 | NetworkThread nt = new NetworkThread(url, mParam); | 186 | NetworkThread nt = new NetworkThread(url, mParam); |
186 | nt.delegate = this; | 187 | nt.delegate = this; |
PremiereActivite/app/src/main/java/com/example/app_10p5/MainActivite.java
@@ -3,16 +3,25 @@ package com.example.app_10p5; | @@ -3,16 +3,25 @@ package com.example.app_10p5; | ||
3 | import android.app.Activity; | 3 | import android.app.Activity; |
4 | import android.app.FragmentManager; | 4 | import android.app.FragmentManager; |
5 | import android.app.FragmentTransaction; | 5 | import android.app.FragmentTransaction; |
6 | +import android.content.Context; | ||
6 | import android.content.Intent; | 7 | import android.content.Intent; |
8 | +import android.graphics.drawable.BitmapDrawable; | ||
7 | import android.graphics.drawable.ColorDrawable; | 9 | import android.graphics.drawable.ColorDrawable; |
8 | import android.os.Bundle; | 10 | import android.os.Bundle; |
9 | -import android.support.design.widget.TabLayout; | ||
10 | import android.support.v4.view.ViewPager; | 11 | import android.support.v4.view.ViewPager; |
12 | +import android.view.Gravity; | ||
13 | +import android.view.LayoutInflater; | ||
11 | import android.view.Menu; | 14 | import android.view.Menu; |
12 | import android.view.MenuInflater; | 15 | import android.view.MenuInflater; |
13 | import android.view.MenuItem; | 16 | import android.view.MenuItem; |
14 | import android.view.View; | 17 | import android.view.View; |
18 | +import android.view.ViewGroup; | ||
19 | +import android.widget.Button; | ||
15 | import android.widget.EditText; | 20 | import android.widget.EditText; |
21 | +import android.widget.FrameLayout; | ||
22 | +import android.widget.LinearLayout; | ||
23 | +import android.widget.PopupMenu; | ||
24 | +import android.widget.PopupWindow; | ||
16 | import android.widget.Toast; | 25 | import android.widget.Toast; |
17 | 26 | ||
18 | import org.json.JSONObject; | 27 | import org.json.JSONObject; |
@@ -51,11 +60,20 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | @@ -51,11 +60,20 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
51 | 60 | ||
52 | getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary))); | 61 | getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary))); |
53 | 62 | ||
54 | - FragmentManager fragmentManager = getFragmentManager(); | ||
55 | - FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); | ||
56 | - main_tab_frag fragment = new main_tab_frag(); | ||
57 | - fragmentTransaction.add(R.id.fragment_container, fragment); | ||
58 | - fragmentTransaction.commit(); | 63 | + if(savedInstanceState == null){ |
64 | + FragmentManager fragmentManager = getFragmentManager(); | ||
65 | + FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); | ||
66 | + main_tab_frag fragment = new main_tab_frag(); | ||
67 | + fragmentTransaction.add(R.id.fragment_container, fragment); | ||
68 | + fragmentTransaction.commit(); | ||
69 | + } | ||
70 | + else{ | ||
71 | + mTimeToken = savedInstanceState.getLong("timeToken"); | ||
72 | + mToken = savedInstanceState.getString("token"); | ||
73 | + mState = savedInstanceState.getInt("state"); | ||
74 | + mUser = savedInstanceState.getString("user"); | ||
75 | + mDroit = savedInstanceState.getInt("droit"); | ||
76 | + } | ||
59 | } | 77 | } |
60 | 78 | ||
61 | @Override | 79 | @Override |
@@ -68,7 +86,16 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | @@ -68,7 +86,16 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
68 | @Override | 86 | @Override |
69 | public boolean onOptionsItemSelected(MenuItem item) { | 87 | public boolean onOptionsItemSelected(MenuItem item) { |
70 | // Handle item selection | 88 | // Handle item selection |
71 | - return super.onOptionsItemSelected(item); | 89 | + if(item.getItemId() == R.id.menu_2_choice_1){ |
90 | + CarteActivite.HOST = "https://10p5.clubinfo.frogeye.fr/"; | ||
91 | + item.setChecked(true); | ||
92 | + } | ||
93 | + else if(item.getItemId() == R.id.menu_2_choice_2){ | ||
94 | + CarteActivite.HOST = "http://pcbar.insecure.deule.net/"; | ||
95 | + item.setChecked(true); | ||
96 | + } | ||
97 | + | ||
98 | + return super.onOptionsItemSelected(item); | ||
72 | } | 99 | } |
73 | 100 | ||
74 | @Override | 101 | @Override |
@@ -87,17 +114,6 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | @@ -87,17 +114,6 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
87 | super.onSaveInstanceState(savedInstanceState); | 114 | super.onSaveInstanceState(savedInstanceState); |
88 | } | 115 | } |
89 | 116 | ||
90 | - @Override | ||
91 | - public void onRestoreInstanceState(Bundle savedInstanceState) { | ||
92 | - mTimeToken = savedInstanceState.getLong("timeToken"); | ||
93 | - mToken = savedInstanceState.getString("user"); | ||
94 | - mState = savedInstanceState.getInt("state"); | ||
95 | - mUser = savedInstanceState.getString("user"); | ||
96 | - mDroit = savedInstanceState.getInt("droit"); | ||
97 | - | ||
98 | - super.onRestoreInstanceState(savedInstanceState); | ||
99 | - } | ||
100 | - | ||
101 | public void valideCreationCompte(View v){ | 117 | public void valideCreationCompte(View v){ |
102 | if((mToken != "") && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) { | 118 | if((mToken != "") && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) { |
103 | EditText champMontant = (EditText) findViewById(R.id.creation_montant); | 119 | EditText champMontant = (EditText) findViewById(R.id.creation_montant); |
@@ -124,8 +140,8 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | @@ -124,8 +140,8 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
124 | } | 140 | } |
125 | else{ | 141 | else{ |
126 | Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show(); | 142 | Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show(); |
127 | - /*final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); | ||
128 | - viewPager.setCurrentItem(0);*/ | 143 | + final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); |
144 | + viewPager.setCurrentItem(0); | ||
129 | } | 145 | } |
130 | } | 146 | } |
131 | 147 | ||
@@ -161,8 +177,8 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | @@ -161,8 +177,8 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
161 | } | 177 | } |
162 | else{ | 178 | else{ |
163 | Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show(); | 179 | Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show(); |
164 | - /*final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); | ||
165 | - viewPager.setCurrentItem(0);*/ | 180 | + final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); |
181 | + viewPager.setCurrentItem(0); | ||
166 | } | 182 | } |
167 | } | 183 | } |
168 | 184 | ||
@@ -193,8 +209,8 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | @@ -193,8 +209,8 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
193 | } | 209 | } |
194 | else{ | 210 | else{ |
195 | Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show(); | 211 | Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show(); |
196 | - /*final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); | ||
197 | - viewPager.setCurrentItem(0);*/ | 212 | + final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); |
213 | + viewPager.setCurrentItem(0); | ||
198 | } | 214 | } |
199 | } | 215 | } |
200 | 216 | ||
@@ -219,7 +235,7 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | @@ -219,7 +235,7 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
219 | nt.execute(); | 235 | nt.execute(); |
220 | } | 236 | } |
221 | catch (Throwable t) { | 237 | catch (Throwable t) { |
222 | - //TODO: gérer les exceptions du cancer de la connexion | 238 | + System.out.println("Exception: " + t.toString()); |
223 | } | 239 | } |
224 | } | 240 | } |
225 | else{ | 241 | else{ |
@@ -243,8 +259,8 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | @@ -243,8 +259,8 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
243 | } | 259 | } |
244 | else{ | 260 | else{ |
245 | Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show(); | 261 | Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show(); |
246 | - /*final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); | ||
247 | - viewPager.setCurrentItem(0);*/ | 262 | + final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); |
263 | + viewPager.setCurrentItem(0); | ||
248 | } | 264 | } |
249 | } | 265 | } |
250 | 266 | ||
@@ -258,7 +274,7 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | @@ -258,7 +274,7 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
258 | 274 | ||
259 | } | 275 | } |
260 | catch (Throwable t){ | 276 | catch (Throwable t){ |
261 | - Toast.makeText(this, "WTF, le cancer est dans l'application!!", Toast.LENGTH_LONG).show(); | 277 | + Toast.makeText(this, "Retour", Toast.LENGTH_SHORT).show(); |
262 | } | 278 | } |
263 | 279 | ||
264 | 280 | ||
@@ -293,8 +309,8 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | @@ -293,8 +309,8 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
293 | Toast.makeText(this, "Bonjour " + mUser + " vous êtes bien connecté pour " + EXPIRATION / (1000 * 60) + " minutes.", Toast.LENGTH_LONG).show(); | 309 | Toast.makeText(this, "Bonjour " + mUser + " vous êtes bien connecté pour " + EXPIRATION / (1000 * 60) + " minutes.", Toast.LENGTH_LONG).show(); |
294 | EditText coUser = (EditText) findViewById(R.id.connection_password); | 310 | EditText coUser = (EditText) findViewById(R.id.connection_password); |
295 | coUser.setText(""); | 311 | coUser.setText(""); |
296 | - /*final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); | ||
297 | - viewPager.setCurrentItem(1);*/ | 312 | + final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); |
313 | + viewPager.setCurrentItem(1); | ||
298 | } | 314 | } |
299 | else{ | 315 | else{ |
300 | Toast.makeText(this, "Erreur dans la requête: " + output.get("status"), Toast.LENGTH_LONG).show(); | 316 | Toast.makeText(this, "Erreur dans la requête: " + output.get("status"), Toast.LENGTH_LONG).show(); |
@@ -316,4 +332,11 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | @@ -316,4 +332,11 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
316 | public long getTimeToken(){ | 332 | public long getTimeToken(){ |
317 | return mTimeToken; | 333 | return mTimeToken; |
318 | } | 334 | } |
335 | + | ||
336 | + public void settingsPopup(View v) { | ||
337 | + PopupMenu popup = new PopupMenu(this, v); | ||
338 | + MenuInflater inflater = popup.getMenuInflater(); | ||
339 | + inflater.inflate(R.menu.popup_settings, popup.getMenu()); | ||
340 | + popup.show(); | ||
341 | + } | ||
319 | } | 342 | } |
PremiereActivite/app/src/main/res/menu/menu.xml
@@ -19,6 +19,13 @@ | @@ -19,6 +19,13 @@ | ||
19 | android:id="@+id/action_settings" | 19 | android:id="@+id/action_settings" |
20 | android:title="@string/action_settings" | 20 | android:title="@string/action_settings" |
21 | android:showAsAction="never" | 21 | android:showAsAction="never" |
22 | - app:showAsAction="never" /> | 22 | + app:showAsAction="never"><menu> |
23 | + <group android:checkableBehavior="single"> | ||
24 | + <item android:id="@+id/menu_2_choice_1" android:title="Geoffrey" android:showAsAction="never" android:checked="true" /> | ||
25 | + <item android:id="@+id/menu_2_choice_2" android:title="Bar" android:showAsAction="never" /> | ||
26 | + </group> | ||
27 | +</menu> | ||
28 | + </item> | ||
29 | + | ||
23 | 30 | ||
24 | </menu> | 31 | </menu> |
25 | \ No newline at end of file | 32 | \ No newline at end of file |