Commit 3c5d3089627c75c608448767cda59f0aba2def46

Authored by JLo'w
1 parent 0aec73b6

Work in progress - plus de NFC

PremiereActivite/app/build.gradle
... ... @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
2 2  
3 3 android {
4 4 compileSdkVersion 23
5   - buildToolsVersion "23.0.3"
  5 + buildToolsVersion '23.2.1'
6 6  
7 7 defaultConfig {
8 8 applicationId "com.example.app_10p5"
... ...
PremiereActivite/app/src/main/java/com/example/app_10p5/CarteActivite.java
... ... @@ -46,6 +46,7 @@ public class CarteActivite extends Activity implements ASyncResponse {
46 46 mAPI = "api/client/ajouter";
47 47 break;
48 48 case MainActivite.STATE_RECHARGEMENT:
  49 + System.out.println("bite");
49 50 mParam.put("montant", String.valueOf(getIntent().getFloatExtra("montant", -1)));
50 51 mParam.put("jeton", getIntent().getStringExtra("token"));
51 52 mAPI = "api/client/recharger";
... ... @@ -179,6 +180,7 @@ public class CarteActivite extends Activity implements ASyncResponse {
179 180  
180 181 public void clientAPI() {
181 182 try {
  183 + System.out.println("chatte");
182 184 URL url = new URL(HOST + mAPI);
183 185 NetworkThread nt = new NetworkThread(url, mParam);
184 186 nt.delegate = this;
... ...
PremiereActivite/app/src/main/java/com/example/app_10p5/MainActivite.java
1 1 package com.example.app_10p5;
2 2  
3 3 import android.app.Activity;
  4 +import android.app.FragmentManager;
  5 +import android.app.FragmentTransaction;
4 6 import android.content.Intent;
5 7 import android.graphics.drawable.ColorDrawable;
6 8 import android.os.Bundle;
... ... @@ -22,7 +24,7 @@ import java.util.HashMap;
22 24 /**
23 25 * Created by beaus on 24/04/2016.
24 26 */
25   -public class MainActivite extends Activity implements ASyncResponse {
  27 +public class MainActivite extends Activity implements ASyncResponse, main_tab_frag.OnFragmentInteractionListener {
26 28  
27 29 public static final int STATE_RIEN = 0;
28 30 public static final int STATE_COMMANDE = 3;
... ... @@ -49,42 +51,11 @@ public class MainActivite extends Activity implements ASyncResponse {
49 51  
50 52 getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary)));
51 53  
52   - TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
53   - tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
54   - tabLayout.addTab(tabLayout.newTab().setText("Connexion"));
55   - tabLayout.addTab(tabLayout.newTab().setText("Commande"));
56   - tabLayout.addTab(tabLayout.newTab().setText("Rechargement"));
57   - tabLayout.addTab(tabLayout.newTab().setText("Création"));
58   - tabLayout.addTab(tabLayout.newTab().setText("Vidange"));
59   - tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
60   -
61   - final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
62   - final PagerAdapter adapter = new PagerAdapter(getFragmentManager(), tabLayout.getTabCount());
63   - viewPager.setAdapter(adapter);
64   - viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
65   - tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
66   - @Override
67   - public void onTabSelected(TabLayout.Tab tab) {
68   - if(mToken != "" && System.currentTimeMillis() - mTimeToken < EXPIRATION){
69   - viewPager.setCurrentItem(tab.getPosition());
70   - }
71   - else{
72   - viewPager.setCurrentItem(tab.getPosition()); //Empeche un bug graphique
73   - viewPager.setCurrentItem(0);
74   - Toast.makeText(MainActivite.this, "Veuillez vous connecter.", Toast.LENGTH_LONG).show();
75   - }
76   - }
77   -
78   - @Override
79   - public void onTabUnselected(TabLayout.Tab tab) {
80   -
81   - }
82   -
83   - @Override
84   - public void onTabReselected(TabLayout.Tab tab) {
85   -
86   - }
87   - });
  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();
88 59 }
89 60  
90 61 @Override
... ... @@ -101,6 +72,11 @@ public class MainActivite extends Activity implements ASyncResponse {
101 72 }
102 73  
103 74 @Override
  75 + public void onFragmentInteraction(String s){
  76 +
  77 + }
  78 +
  79 + @Override
104 80 public void onSaveInstanceState(Bundle savedInstanceState){
105 81 savedInstanceState.putString("token", mToken);
106 82 savedInstanceState.putInt("state", mState);
... ... @@ -148,8 +124,8 @@ public class MainActivite extends Activity implements ASyncResponse {
148 124 }
149 125 else{
150 126 Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show();
151   - final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
152   - viewPager.setCurrentItem(0);
  127 + /*final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
  128 + viewPager.setCurrentItem(0);*/
153 129 }
154 130 }
155 131  
... ... @@ -185,8 +161,8 @@ public class MainActivite extends Activity implements ASyncResponse {
185 161 }
186 162 else{
187 163 Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show();
188   - final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
189   - viewPager.setCurrentItem(0);
  164 + /*final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
  165 + viewPager.setCurrentItem(0);*/
190 166 }
191 167 }
192 168  
... ... @@ -217,8 +193,8 @@ public class MainActivite extends Activity implements ASyncResponse {
217 193 }
218 194 else{
219 195 Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show();
220   - final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
221   - viewPager.setCurrentItem(0);
  196 + /*final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
  197 + viewPager.setCurrentItem(0);*/
222 198 }
223 199 }
224 200  
... ... @@ -267,8 +243,8 @@ public class MainActivite extends Activity implements ASyncResponse {
267 243 }
268 244 else{
269 245 Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_LONG).show();
270   - final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
271   - viewPager.setCurrentItem(0);
  246 + /*final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
  247 + viewPager.setCurrentItem(0);*/
272 248 }
273 249 }
274 250  
... ... @@ -317,8 +293,8 @@ public class MainActivite extends Activity implements ASyncResponse {
317 293 Toast.makeText(this, "Bonjour " + mUser + " vous êtes bien connecté pour " + EXPIRATION / (1000 * 60) + " minutes.", Toast.LENGTH_LONG).show();
318 294 EditText coUser = (EditText) findViewById(R.id.connection_password);
319 295 coUser.setText("");
320   - final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
321   - viewPager.setCurrentItem(1);
  296 + /*final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
  297 + viewPager.setCurrentItem(1);*/
322 298 }
323 299 else{
324 300 Toast.makeText(this, "Erreur dans la requête: " + output.get("status"), Toast.LENGTH_LONG).show();
... ... @@ -332,4 +308,12 @@ public class MainActivite extends Activity implements ASyncResponse {
332 308 Toast.makeText(this, "Impossible de se connecter au serveur", Toast.LENGTH_LONG).show();
333 309 }
334 310 }
  311 +
  312 + public String getToken(){
  313 + return mToken;
  314 + }
  315 +
  316 + public long getTimeToken(){
  317 + return mTimeToken;
  318 + }
335 319 }
... ...
PremiereActivite/app/src/main/java/com/example/app_10p5/main_tab_frag.java 0 → 100644
... ... @@ -0,0 +1,87 @@
  1 +package com.example.app_10p5;
  2 +
  3 +import android.app.Activity;
  4 +import android.content.Context;
  5 +import android.os.Bundle;
  6 +import android.app.Fragment;
  7 +import android.support.design.widget.TabLayout;
  8 +import android.support.v4.view.ViewPager;
  9 +import android.view.LayoutInflater;
  10 +import android.view.View;
  11 +import android.view.ViewGroup;
  12 +import android.widget.Toast;
  13 +
  14 +
  15 +public class main_tab_frag extends Fragment {
  16 +
  17 +
  18 + public main_tab_frag() {
  19 + }
  20 +
  21 + @Override
  22 + public void onCreate(Bundle savedInstanceState) {
  23 + super.onCreate(savedInstanceState);
  24 + }
  25 +
  26 + @Override
  27 + public View onCreateView(LayoutInflater inflater, ViewGroup container,
  28 + Bundle savedInstanceState) {
  29 + // Inflate the layout for this fragment
  30 + View ret = inflater.inflate(R.layout.fragment_main_tab_frag, container, false);
  31 +
  32 + final MainActivite parent = (MainActivite) getActivity();
  33 +
  34 + TabLayout tabLayout = (TabLayout) ret.findViewById(R.id.tab_layout);
  35 + tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
  36 + tabLayout.addTab(tabLayout.newTab().setText("Connexion"));
  37 + tabLayout.addTab(tabLayout.newTab().setText("Commande"));
  38 + tabLayout.addTab(tabLayout.newTab().setText("Rechargement"));
  39 + tabLayout.addTab(tabLayout.newTab().setText("Création"));
  40 + tabLayout.addTab(tabLayout.newTab().setText("Vidange"));
  41 + tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
  42 +
  43 + final ViewPager viewPager = (ViewPager) ret.findViewById(R.id.pager);
  44 + final PagerAdapter adapter = new PagerAdapter(getFragmentManager(), tabLayout.getTabCount());
  45 + viewPager.setAdapter(adapter);
  46 + viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
  47 + tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
  48 + @Override
  49 + public void onTabSelected(TabLayout.Tab tab) {
  50 + if(parent.getToken() != "" && System.currentTimeMillis() - parent.getTimeToken() < MainActivite.EXPIRATION){
  51 + viewPager.setCurrentItem(tab.getPosition());
  52 + }
  53 + else{
  54 + viewPager.setCurrentItem(tab.getPosition()); //Empeche un bug graphique
  55 + viewPager.setCurrentItem(0);
  56 + Toast.makeText(parent, "Veuillez vous connecter.", Toast.LENGTH_LONG).show();
  57 + }
  58 + }
  59 +
  60 + @Override
  61 + public void onTabUnselected(TabLayout.Tab tab) {
  62 +
  63 + }
  64 +
  65 + @Override
  66 + public void onTabReselected(TabLayout.Tab tab) {
  67 +
  68 + }
  69 + });
  70 +
  71 + return ret;
  72 + }
  73 +
  74 + @Override
  75 + public void onAttach(Context context) {
  76 + super.onAttach(context);
  77 + }
  78 +
  79 + @Override
  80 + public void onDetach() {
  81 + super.onDetach();
  82 + }
  83 +
  84 + public interface OnFragmentInteractionListener {
  85 + void onFragmentInteraction(String s);
  86 + }
  87 +}
... ...
PremiereActivite/app/src/main/res/layout/fragment_main_tab_frag.xml 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2 + xmlns:tools="http://schemas.android.com/tools"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent"
  5 + tools:context="com.example.app_10p5.main_tab_frag"
  6 + android:orientation="vertical">
  7 +
  8 + <android.support.design.widget.TabLayout
  9 + android:id="@+id/tab_layout"
  10 + android:layout_width="match_parent"
  11 + android:layout_height="wrap_content"
  12 + android:background="?attr/colorPrimary"
  13 + android:elevation="6dp"
  14 + android:minHeight="75dp"/>
  15 +
  16 + <android.support.v4.view.ViewPager
  17 + android:id="@+id/pager"
  18 + android:layout_width="match_parent"
  19 + android:layout_height="fill_parent" />
  20 +
  21 +</LinearLayout>
... ...
PremiereActivite/app/src/main/res/layout/layout_main.xml
1 1 <?xml version="1.0" encoding="utf-8"?>
2   -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3   - xmlns:tools="http://schemas.android.com/tools"
4   - android:layout_width="match_parent"
5   - android:layout_height="match_parent"
6   - tools:context=".MainActivite"
7   - android:orientation="vertical">
8   -
9   - <android.support.design.widget.TabLayout
10   - android:id="@+id/tab_layout"
  2 +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:id="@+id/fragment_container"
11 4 android:layout_width="match_parent"
12   - android:layout_height="wrap_content"
13   - android:background="?attr/colorPrimary"
14   - android:elevation="6dp"
15   - android:minHeight="75dp"/>
16   -
17   - <android.support.v4.view.ViewPager
18   - android:id="@+id/pager"
19   - android:layout_width="match_parent"
20   - android:layout_height="fill_parent" />
21   -
22   -</LinearLayout>
23 5 \ No newline at end of file
  6 + android:layout_height="match_parent"
  7 + android:background="?android:attr/detailsElementBackground" />
... ...
PremiereActivite/app/src/main/res/values/strings.xml
... ... @@ -12,4 +12,7 @@
12 12 <string name="disconnect">Déconnexion</string>
13 13 <string name="connect">Connexion</string>
14 14  
  15 + <!-- TODO: Remove or change this placeholder text -->
  16 + <string name="hello_blank_fragment">Hello blank fragment</string>
  17 +
15 18 </resources>
... ...