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
| package com.lettres;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import controleur.Controleur;
public class MainActivity extends Activity {
private Controleur controleur;
@Override
protected void onCreate(Bundle savedInstanceState) {
//Constructeur classe Activity
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_principal);
//Instanciation du controleur en lui passant l'activité
controleur = new Controleur(this);
}
//METHODES
public void clickLettre(View v)
{
if(v instanceof TextView){
//recupérer Lettre
TextView tv = (TextView) v;
//envoyer au controleur (la view en parametre)
controleur.clickLettre(tv);
}
}
public void desactiverLettre(View v)
{
if(v instanceof TextView)
{
TextView tv = (TextView) v;
tv.setClickable(false);
tv.setTextColor(Color.GRAY);
}
}
public void activerLettres()
{
ArrayList<TextView> textViewList = new ArrayList<TextView>();
//On récupčre tous les TextView des lettres en bouclant sur les 3 layouts les contenant.
int layout1ID = this.getResources().getIdentifier("alphaLine1", "id", this.getPackageName());
int layout2ID = this.getResources().getIdentifier("alphaLine2", "id", this.getPackageName());
int layout3ID = this.getResources().getIdentifier("alphaLine3", "id", this.getPackageName());
LinearLayout[] ly = {(LinearLayout) (this.findViewById(layout1ID)),
(LinearLayout) (this.findViewById(layout2ID)),
(LinearLayout) (this.findViewById(layout3ID))};
for(LinearLayout l : ly)
{
for( int i = 0; i < l.getChildCount(); i++ )
if( l.getChildAt( i ) instanceof TextView && !(l.getChildAt( i ) instanceof Button))
textViewList.add( (TextView) l.getChildAt( i ) );
}
//On réactive toutes les lettres obtenues.
for(TextView t : textViewList)
{
t.setClickable(true);
t.setTextColor(Color.WHITE);
}
}
public void afficherMotEnCours(String strReponse)
{
String finalString = "";
char[] charReponse = strReponse.toCharArray();
for(int i=0 ; i< charReponse.length ; i++)
{
if(i != charReponse.length-1)
{
finalString += charReponse[i];
finalString += " "; //On ajoute des espaces entre chaque charactère pour un affichage plus clair.
}
else
{
finalString += charReponse[i];
}
}
//On affiche
TextView tv = (TextView) this.findViewById(this.getResources().getIdentifier("affichMot", "id", this.getPackageName()));
tv.setText(finalString);
}
public void afficherImage(String chemin)
{
//récupérer chemin vers dossier file de l'appli
// File picture = this.getFilesDir();
// File drawableFile = new File(getApplicationContext().getFilesDir().getAbsolutePath() + chemin);
// ImageView iv = (ImageView) this.findViewById(this.getResources().getIdentifier("image", "id", this.getPackageName()));
ImageView iv = (ImageView) this.findViewById(R.id.image);
int ident = getResources().getIdentifier(chemin, "drawable", getPackageName());
// Drawable d = Drawable.createFromPath(picture.getAbsolutePath());
// iv.setBackgroundResource(ident);
iv.setImageResource(ident);
// iv.setImageDrawable(d);
}
public void desactiverToutesLettres() {
ArrayList<TextView> textViewList = new ArrayList<TextView>();
//On récupère tous les TextView des lettres en bouclant sur les 3 layouts les contenant.
int layout1ID = this.getResources().getIdentifier("alphaLine1", "id", this.getPackageName());
int layout2ID = this.getResources().getIdentifier("alphaLine2", "id", this.getPackageName());
int layout3ID = this.getResources().getIdentifier("alphaLine3", "id", this.getPackageName());
LinearLayout[] ly = {(LinearLayout) (this.findViewById(layout1ID)),
(LinearLayout) (this.findViewById(layout2ID)),
(LinearLayout) (this.findViewById(layout3ID))};
for(LinearLayout l : ly)
{
for( int i = 0; i < l.getChildCount(); i++ )
if( l.getChildAt( i ) instanceof TextView )
textViewList.add( (TextView) l.getChildAt( i ) );
}
//On désactive toutes les lettres obtenues sans changer les couleurs
for(TextView t : textViewList)
{
t.setClickable(false);
}
System.out.println("temp");
}
//Aprés click sur le bouton "Nouveau mot"
public void nouveauMot(View v)
{
controleur.nouveauMot();
}
//Appelé depuis le controleur
public void resetImage() {
ImageView iv = (ImageView) this.findViewById(this.getResources().getIdentifier("image", "id", this.getPackageName()));
iv.setImageResource(R.drawable.ic_launcher);
}
} |
Partager