Blame view

PremiereActivite/app/src/main/java/com/example/app_10p5/TabFragment1.java 2.62 KB
c8059613   JLo'w   Re-fonte de l'app...
1
2
3
  package com.example.app_10p5;
  
  import android.os.Bundle;
e9b6c14d   JLo'w   Passage au suppor...
4
  import android.app.Fragment;
3cc8c195   JLo'w   On désactive les ...
5
  import android.text.Editable;
76de4d29   JLo'w   Connexion et NFC ...
6
  import android.text.InputFilter;
3cc8c195   JLo'w   On désactive les ...
7
  import android.text.TextWatcher;
c8059613   JLo'w   Re-fonte de l'app...
8
9
10
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
3cc8c195   JLo'w   On désactive les ...
11
  import android.widget.Button;
76de4d29   JLo'w   Connexion et NFC ...
12
  import android.widget.EditText;
c8059613   JLo'w   Re-fonte de l'app...
13
  
3cc8c195   JLo'w   On désactive les ...
14
15
  import java.util.ArrayList;
  
93f90e35   JLo'w   NFC et foreground
16
17
18
19
  /**
   * Created by beaus on 24/04/2016.
   */
  
c8059613   JLo'w   Re-fonte de l'app...
20
21
22
  public class TabFragment1 extends Fragment {
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
76de4d29   JLo'w   Connexion et NFC ...
23
24
          View v = inflater.inflate(R.layout.tab_fragment_1, container, false);
          EditText et = (EditText) v.findViewById(R.id.commande_prix);
3cc8c195   JLo'w   On désactive les ...
25
  
76de4d29   JLo'w   Connexion et NFC ...
26
27
          et.setFilters(new InputFilter[]{new DecimalDigitsInputFilter(3, 2)});
  
3cc8c195   JLo'w   On désactive les ...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
          final ArrayList<View> allChildren = getAllChildren(v.findViewById(R.id.commande_table_boutons));
          et.addTextChangedListener(new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence s, int start, int count, int after) {
              }
  
              @Override
              public void onTextChanged(CharSequence s, int start, int before, int count) {
  
                  if(s.toString().trim().length() != 0){
                      for (View child : allChildren) {
                          if (child instanceof Button) {
                              Button bouton = (Button) child;
                              bouton.setEnabled(false);
                          }
                      }
                  }
                  else{
                      for (View child : allChildren) {
                          if (child instanceof Button) {
                              Button bouton = (Button) child;
                              bouton.setEnabled(true);
                          }
                      }
                  }
  
              }
  
              @Override
              public void afterTextChanged(Editable s) {
  
              }
          });
  
76de4d29   JLo'w   Connexion et NFC ...
62
          return v;
c8059613   JLo'w   Re-fonte de l'app...
63
      }
3cc8c195   JLo'w   On désactive les ...
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  
      private ArrayList<View> getAllChildren(View v) {
  
          if (!(v instanceof ViewGroup)) {
              ArrayList<View> viewArrayList = new ArrayList<View>();
              viewArrayList.add(v);
              return viewArrayList;
          }
  
          ArrayList<View> result = new ArrayList<View>();
  
          ViewGroup vg = (ViewGroup) v;
          for (int i = 0; i < vg.getChildCount(); i++) {
  
              View child = vg.getChildAt(i);
  
              ArrayList<View> viewArrayList = new ArrayList<View>();
              viewArrayList.add(v);
              viewArrayList.addAll(getAllChildren(child));
  
              result.addAll(viewArrayList);
          }
          return result;
      }
c8059613   JLo'w   Re-fonte de l'app...
88
  }