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
| thereIsSomethingToShow=true;
//Envoyer la requête au site
t1 = new Thread(new Runnable() //ReservationInfo.this.runOnUiThread(new Runnable() -> si je mets ça ici, l'app plante!
{
public void run()
{
Looper.prepare();
StringBuffer stringBuffer = new StringBuffer("");
BufferedReader bufferedReader = null;
URI uri = null;
try
{
requestAndMakeSheet(stringBuffer, bufferedReader, uri);
}
catch (Exception e)
{
thereIsSomethingToShow=false;
ReservationInfo.this.runOnUiThread(new Runnable()
{
public void run()
{
AlertDialog.Builder parsingErrorBox = new AlertDialog.Builder(ReservationInfo.this);
parsingErrorBox.setTitle("Login error");
parsingErrorBox.setMessage("You may have to check your credentials and then try again.");
parsingErrorBox.setNeutralButton("OK",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
});
parsingErrorBox.show();
}
});
}
finally
{
if (bufferedReader!=null)
{
try
{
bufferedReader.close();
}
catch (IOException ioe)
{
Log.e("Web Request Error", ioe.getMessage());
}
}
}
}
});
t1.start();
try
{
t1.join();
if (thereIsSomethingToShow)
{
mWebview.loadUrl("file:///"+Environment.getExternalStorageDirectory()+"/ReservationSheet3.html");
setContentView(mWebview);
}
else
{
//Return to main activity
Intent myIntent = new Intent(this.getBaseContext(), MainActivity.class);
startActivityForResult(myIntent, 0);
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
} |
Partager