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
|
package com.quickpl.quickpl;
import java.io.File;
import java.io.Writer;
import java.io.FileOutputStream;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
// tableau instantié pour enregister les PL
String tableau[] = new String[9];
//tableau utiliser pour créer les entete de colonne pour le fichier CSV
String headerIcaps[] = {"Revision Number", "Revision Type", "Associated Category Code","Associated Equipment Number","Associated Discipline Code", "Defect Description", "Originated By", "Action By", "Originated Date"};
//variable ----
int row = 10; //nombre de ligne dans la matrice de PL //new
int col = 8; // nombre de colonne dans la matrice de PL //new
int lign = 1; //variable d'incrémant pour compter les lignes déjà écrite
String tableauMulti[][] = new String [row][col]; //new
//déclaration des widgets ------------------------------------------
private EditText fillItem;
private TextView itemTitre;
private EditText fillSubject;
private Button validPl;
private Button clearView;
private Button exportPl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fillItem = (EditText) findViewById(R.id.fillItem);
itemTitre = (TextView) findViewById(R.id.itemTitre);
fillSubject = (EditText) findViewById(R.id.fillSubject);
validPl = (Button) findViewById(R.id.validPl);
clearView = (Button) findViewById(R.id.clearView);
exportPl = (Button) findViewById(R.id.exportPl);
validPl.setOnClickListener(validPlListener);
clearView.setOnClickListener(clearViewListener);
exportPl.setOnClickListener(exportPlListener);
init();
}
private void init() { /* classe d'initialisation des valeurs */
}
// BOUTON action pour enregister la PL saisie dans un tableau par bouton "Valider"----------------------------------
private View.OnClickListener validPlListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (lign<2) {
//remplicage du header des colonnes //new
tableauMulti[0][0] = "Revision Number";
tableauMulti[0][1] = "Revision Type";
tableauMulti[0][2] = "Associated Category";
tableauMulti[0][3] = "Associated Discipline Code";
tableauMulti[0][4] = "Defect Description";
tableauMulti[0][5] = "Originated By";
tableauMulti[0][6] = "Action By";
tableauMulti[0][7] = "Originated Date";
}
// enregistrement des valeurs editText en valeur String dans de nouvelles variables
String fillItemString = fillItem.getText().toString();
String fillSubjectString = fillSubject.getText().toString();
// ------------------------------------------------
// transfert des variables saisie dans une ligne dedie
lign = lign++;
tableauMulti[lign][0] = "1";
tableauMulti[lign][1] = "C";
tableauMulti[lign][2] = "";
tableauMulti[lign][3] = fillItemString;
tableauMulti[lign][4] ="";
tableauMulti[lign][5] = fillSubjectString;
tableauMulti[lign][6] = "";
tableauMulti[lign][7] = "";
// ----------------------------------------------------
// ici j'initialise les edit text de saisie
fillItem.setText("");
fillSubject.setText("");
// -------------------------------------------
}
}; // FIN BOUTON -----------------------------------------------------
// BOUTON action d'exporter les PL enregistré dans les tableau dans un fichier CSV
private View.OnClickListener exportPlListener; // FIN BOUTON -----------------------------------------------------
{
exportPlListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("DEBUG", "Bouton cliqué"); // ligne de log pour suivre la déroulement du programme)
// convertion du contenu du tableau dans un fichier CSV
File myFile = new File(Environment.getExternalStorageDirectory() + File.separator + "quickPL", "testAppli.csv");
File myDir = new File(Environment.getExternalStorageDirectory() + File.separator + "quickPL"); //pour créer le repertoire dans lequel on va mettre notre fichier
Boolean success = true;
if (!myDir.exists()) {
success = myDir.mkdir(); //On crée le répertoire (s'il n'existe pas!!)
}
if (success) {
String data1 = myFile.getName();
try {
FileOutputStream output = new FileOutputStream(myFile);
for (int l =0; l < tableauMulti.length; l++){
for (int c = 0; c <= 7; c++){
output.write((tableauMulti[l][c]+";").getBytes());
}
output.write("\r\n".getBytes());
}
output.close();
} catch (IOException e) {
System.out.println(e);
}
} else {
Log.e("TEST1", "ERROR DE CREATION DE DOSSIER");
}
}
}; // FIN BOUTON
}
// BOUTON action de supprimer toutes les saisie sans enregistrer de PL action sur bouton "Clean" --------------------
private View.OnClickListener clearViewListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
fillItem.setText("");
fillSubject.setText("");
}
}; // FIN BOUTON
} |
Partager