1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
|
package com.example.jeux;
import com.example.jeux.R.id;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.InputFilter;
import android.text.InputType;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
public class FragmentBelotte extends Fragment
{
LinearLayout LinearB1;
TextView Info;
TextView btnInfoPartie1;
EditText NomJ;
EditText[] et = new EditText[4];
TextView[] tv = new TextView[4];
Button[] btn = new Button[4];
Button creationFS;
View[] espace = new View[4];
LinearLayout test;
LinearLayout test1;
LinearLayout LLGlobal;
LinearLayout LLChamp;
LinearLayout LLIntro;
LinearLayout LLBtnValidation;
TableRow tabDonnees1;
LayoutParams layoutParams;
TableLayout tabDefautCapteur1;
ScrollView defilementTab;
//LinearLayout.LayoutParams TEST;
//LinearLayout.LayoutParams TEST1;
//LinearLayout.LayoutParams TEST2;
String nomsParticipants="";
int Etat=0;
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
{
View v=inflater.inflate(R.layout.activity_fragment_belotte, container, false);
LinearBelotte1=(LinearLayout)v.findViewById(id.LayoutB);
Log.e("FragmentB.class","Etat -> "+Etat);
btnInfoPartie1=(TextView)v.findViewById(id.btnInfoPartie);
btnInfoPartie1.setText("Cliquer ICI\nPour ouvrir une feuille de score\nD'un jeu de B");
btnInfoPartie1.setGravity(Gravity.CENTER);
if(Etat==1)
DebutPartie();
if(Etat==2)
CreationScoreTableau(nomsParticipants);
return v;
}
public void CreationScoreTableau(String NmParticipants)
{
Etat=2;
Toast toast=Toast.makeText(getActivity(),NmParticipants , Toast.LENGTH_LONG);
TextView yy = (TextView)toast.getView().findViewById(android.R.id.message);
if( yy != null) yy.setGravity(Gravity.CENTER);
toast.show();
LinearB1.removeAllViewsInLayout();
LinearB1.setOrientation(LinearLayout.VERTICAL);
/*
LinearLayout.LayoutParams TEST = new LinearLayout.LayoutParams(LinearLayout.LayoutParams. FILL_PARENT ,LinearLayout.LayoutParams. FILL_PARENT) ;
TextView test = new TextView(getActivity());
test.setText("S'affiche bien");
LinearBelotte1.addView(test,TEST);
*/
LinearLayout.LayoutParams TEST = new LinearLayout.LayoutParams(LinearLayout.LayoutParams. FILL_PARENT ,LinearLayout.LayoutParams. FILL_PARENT) ;
LinearLayout.LayoutParams TEST1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams. FILL_PARENT ,LinearLayout.LayoutParams. WRAP_CONTENT) ;
LinearLayout.LayoutParams TEST2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams. FILL_PARENT ,LinearLayout.LayoutParams. FILL_PARENT) ;
TEST2.setMargins(2, 2, 2, 2);
tabDefautCapteur1= new TableLayout(getActivity());
tabDonnees1 = new TableRow(getActivity());
tabDonnees1.setLayoutParams(TEST1);
tabDonnees1.addView(generateTextView("Heures", TEST2,0));
tabDonnees1.addView(generateTextView("Capteur", TEST2,0));
tabDonnees1.addView(generateTextView("N°", TEST2,0));
tabDonnees1.addView(generateTextView("Donnees", TEST2,0));
tabDonnees1.addView(generateTextView("Rafraichissement", TEST2,0));
// On attribut a la ligne du tableau les diffèrentes cases crées
tabDefautCapteur1.addView(tabDonnees1,TEST2);
LinearBelotte1.addView(tabDefautCapteur1,TEST);
}
public TextView generateTextView(String texte, LayoutParams ly,int ind)
{
// Création d'un nouvelle élément de type TextView
TextView result = new TextView(getActivity());
// en fonction de la valeur de ind on attribut diffèrent paramètre
switch(ind)
{
case 0:
// Attribution d'une couleur de fond
result.setBackgroundColor(Color.parseColor("#8781ff"));
// Attribution du couleur pour les caractères
result.setTextColor(Color.parseColor("#0900b0"));
// Modification de la taille des caractères
result.setTextSize(25);
break;
case 1:
result.setBackgroundColor(Color.LTGRAY);
result.setTextColor(Color.DKGRAY);
result.setTextSize(20);
break;
case 2:
result.setBackgroundColor(Color.parseColor("#ffbb71"));
result.setTextColor(Color.parseColor("#f07d00"));
result.setTextSize(20);
break;
}
// On centre le texte
result.setGravity(Gravity.CENTER);
// Attribution d'une marge
result.setPadding(2, 2, 2, 2);
result.setText(texte);
result.setVisibility(View.VISIBLE);
result.setLayoutParams(ly);
// on renvoi l'élément crée et paramétré
return result;
}
android.view.View.OnClickListener btnValidation = new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
//et[arg0.getId()].clearFocus();
if(arg0.getId()==999)
{
int Validation=0;
for(int i=0;i<4;i++)
{
if(!et[i].getText().toString().equals("..."))
{
nomsParticipants+=et[i].getText().toString()+";";
Validation+=1;
Log.w("FragmentB.class","Le joueur N°"+i+" a un nom");
}
else
{
String msg="Le joueur N°"+(i+1)+" n'a pas de nom";
Toast toast=Toast.makeText(getActivity(),msg , Toast.LENGTH_SHORT);
TextView yy = (TextView)toast.getView().findViewById(android.R.id.message);
if( yy != null) yy.setGravity(Gravity.CENTER);
toast.show()
Log.w("FragmentB.class","Le joueur N°"+i+" n'a pas de nom");
nomsParticipants="";
return;
}
}
if(Validation==4)
{
Log.w("FragmentB.class","Création du tableau");
CreationScoreTableau(nomsParticipants);
}
}
}
};
android.view.View.OnTouchListener NomJoueur = new View.OnTouchListener()
{
@Override
public boolean onTouch(View arg0, MotionEvent arg1)
{
// TODO Auto-generated method stub
//Log.d("FragmentB.class","NomJoueur "+arg0.getId()+" --> "+arg1.toString());
et[arg0.getId()].setText("");
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(et[arg0.getId()].getWindowToken(), 0);
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,0);
//arg1.setAction(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
return false;
}
};
public void DebutPartie()
{
Etat=1;
LinearLayout.LayoutParams LP1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams. FILL_PARENT ,LinearLayout.LayoutParams. FILL_PARENT) ;
LinearLayout.LayoutParams LP2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams. FILL_PARENT ,LinearLayout.LayoutParams. FILL_PARENT) ;
LinearLayout.LayoutParams LP3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams. FILL_PARENT ,LinearLayout.LayoutParams. FILL_PARENT) ;
LP1.weight=1;
LP3.weight=(float) 1.2;
LP2.weight=(float)2.5;
Log.e("FragmentB.class","Etat -> "+Etat);
LinearB1.removeAllViewsInLayout();
//LinearB1.setGravity(Gravity.CENTER_HORIZONTAL);
LLGlobal=new LinearLayout(getActivity());
LLGlobal.setOrientation(LinearLayout.VERTICAL);
LLIntro= new LinearLayout(getActivity());
LLIntro.setOrientation(LinearLayout.VERTICAL);
Info=new TextView(getActivity());
Info.setText("Entrer le noms des 4 joueurs");
Info.setTypeface(Typeface. defaultFromStyle (Typeface. BOLD ));
Info.setTextSize(25);
Info.setGravity(Gravity.CENTER);
LLIntro.setBackgroundColor(Color.YELLOW);
LLIntro.addView( Info , LP1 );
LLGlobal.addView( LLIntro , LP2 );
LLChamp= new LinearLayout(getActivity());
LLChamp.setOrientation(LinearLayout.VERTICAL);
for(int i=0; i<4; i++)
{
test1=new LinearLayout(getActivity());
test1.setOrientation(LinearLayout.VERTICAL);
espace[i]=new View(getActivity());
espace[i].setBackgroundColor(Color.BLUE);
test1.addView(espace[i]);
LLChamp.addView(test1,LP3);
test=new LinearLayout(getActivity());
test.setOrientation(LinearLayout.HORIZONTAL);
//test.setBackgroundColor(Color.BLUE);
tv[i]= new TextView(getActivity());
tv[i].setTextSize(30);
tv[i].setText("Joueur "+(i+1)+" -> ");
//tv[i].setBackgroundColor(Color.MAGENTA);
//tv[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
test.addView(tv[i]);
et[i] = new EditText(getActivity());
et[i].setBackgroundColor(Color.parseColor("#e0dede"));
et[i].setSingleLine();
et[i].setTextSize(20);
et[i].setMinimumWidth(100);
et[i].setGravity(Gravity.CENTER_HORIZONTAL);
et[i].setOnTouchListener(NomJoueur);
et[i].setFilters(new InputFilter[] {new InputFilter.LengthFilter(10)});
et[i].setInputType(InputType.TYPE_CLASS_TEXT);
et[i].setImeOptions(EditorInfo.IME_ACTION_DONE);
et[i].setId(i);
et[i].setText("...");
test.setGravity(Gravity.CENTER);
test.setBackgroundColor(Color.CYAN);
LLChamp.addView(test,LP1);
}
LLGlobal.addView( LLChamp , LP1 );
LLBtnValidation=new LinearLayout(getActivity());
LLBtnValidation.setOrientation(LinearLayout.VERTICAL);
LLBtnValidation.setBackgroundColor(Color.RED);
creationFS= new Button(getActivity());
creationFS.setText("Création Feuille de Score");
creationFS.setId(999);
creationFS.setOnClickListener(btnValidation);
LLBtnValidation.addView( creationFS , LP1 );
LLGlobal.addView( LLBtnValidation , LP2 );
LinearB1.addView(LLGlobal,LP1);
}
} |
Partager