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
| package com.test.train;
import java.io.IOException;
import java.util.ArrayList;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
public class AsyncTraiterPdf extends AsyncTask<Bundle, Void, Void>
{
private static PdfManager pdfManager;
private static final String pdfPath = "/storage/sdcard0/download/Train.pdf";
private String[] lirePages(int pageDebut, int pageFin)
{
String buffer = "";
try
{
buffer = pdfManager.ToText(pageDebut, pageFin);
}
catch (IOException e1)
{
// TODO Auto-generated catch block
Log.e(">>>********ERREUR fichier PDF ", pdfManager.toString());
e1.printStackTrace();
//afficher un message ("ERREUR fichier non trouvé!") d'info à l'écran!!
}
return buffer.split("\\r?\\n");
}
private ArrayList<String> rechercheLignesParArret(String[] lines, String arret)
{
ArrayList<String> linesOK = new ArrayList<String>();
int indice = 0;
try
{
while (!lines[indice].isEmpty())
{
if (lines[indice].indexOf(arret) != -1)
{
linesOK.add(lines[indice]);
}
indice += 1;
}
}
catch (ArrayIndexOutOfBoundsException e)
{
//e.printStackTrace();
}
return linesOK;
}
private void extractionColonnes(ArrayList<String> linesOK)
{
for(int indice = 0; indice <linesOK.size(); indice ++)
{
String cols[] = linesOK.get(indice).toString().split("\\s+");
for(int j= 2; j< cols.length; j++)
{
cols[j] = cols[j].replace('.', ':');
Log.e(">>>******** colonne " +j+": ",cols[j]);
//stockage en base restant à faire
//************************
//insertHoraire(cols[j]);
}
}
}
@Override
protected void onPreExecute()
{
super.onPreExecute();
pdfManager = new PdfManager();
pdfManager.setFilePath(pdfPath);
}
@Override
protected Void doInBackground(Bundle... params)
{
int pageDebut=0, pageFin=0, sens=0;
String arret = "";
//*******
//page n°1
//*******
pageDebut = 1; pageFin = 1; arret = "Gare"; sens = 1;
String lines[] = lirePages(pageDebut, pageFin);
ArrayList<String> linesArret = rechercheLignesParArret(lines, arret);
extractionColonnes(linesArret);
Log.e("********************FIN","sens "+ sens);
Log.e(" "," ");
//*******
//page n°3:
//*******
pageDebut = 3; pageFin = 3; arret = "Centre"; sens = 2;
lines = lirePages(pageDebut, pageFin);
linesArret = rechercheLignesParArret(lines, arret);
extractionColonnes(linesArret);
Log.e("********************FIN","sens "+ sens);
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
}
@Override
protected void onCancelled() {
super.onCancelled();
}
} |
Partager