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
|
private void nuclearRequest(final Bundle bundle)
{
//Send request to website
t1 = new Thread(new Runnable()
{
public void run()
{
Looper.prepare();
StringBuffer stringBuffer = new StringBuffer("");
BufferedReader bufferedReader = null;
URI uri = null;
Log.i("goCheckOnline", bundle.getString("goCheckOnline"));
if (bundle.getString("goCheckOnline").equals("Yes"))
{
//Check Internet connectivity
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
try
{
int networkType = networkInfo.getType();
android.net.NetworkInfo.State networkState = networkInfo.getState();
if (networkState.compareTo(android.net.NetworkInfo.State.CONNECTED)==0)
{
requestAndMakeSheet(stringBuffer, bufferedReader, uri);
if (!rdb.containsReference(Ref))
{
rdb.insertReservation(new Reservation(Ref, Name, 1));
}
}
else
{
Toast.makeText(getBaseContext(), "Please check your Internet connection and then try again.", Toast.LENGTH_LONG).show();
//Return to main activity
Intent myIntent = new Intent(getBaseContext(), MainActivity.class);
myIntent.putExtra("Ref", Ref);
myIntent.putExtra("Name", Name);
startActivityForResult(myIntent, 0);
}
}
catch (NullPointerException n)
{
//n.printStackTrace();
//Toast.makeText(getBaseContext(), "A NullPointerException has occured.", Toast.LENGTH_LONG).show();
displayBox("No connnection", "You may be using Airplane mode. It must be switched off in order to check your trip.");
thereIsSomethingToShow = false;
}
catch (URISyntaxException urle)
{
uponExceptionCatch();
}
catch (IOException ioe)
{
uponExceptionCatch();
}
catch (ParsingException pe)
{
uponExceptionCatch();
}
finally
{
//Hide progress dialog
//progressDialog.dismiss();
if (bufferedReader!=null)
{
try
{
bufferedReader.close();
}
catch (IOException ioe)
{
Log.e("Error closing buffer", ioe.getMessage());
}
}
}
} //End of "if goCheckOnline"
progressDialog.dismiss();
} //End of "run" method
});
t1.start();
try
{
t1.join();
if (thereIsSomethingToShow)
{
File dir = getDir("MyApp", MODE_WORLD_READABLE);
File newfile = new File(dir.getAbsolutePath() + File.separator + Ref+"-"+Name+".html");
mWebview.loadUrl("file://"+dir.getAbsolutePath()+File.separator+Ref+"-"+Name+".html"); //("file:///"+Environment.getExternalStorageDirectory()/*+"//MyApp//ReservationSheets//"*/+"//"+Ref+"-"+Name+".html");
setContentView(mWebview);
if (bundle.getString("goCheckOnline").equals("No"))
{
Toast.makeText(getBaseContext(), "This is an offline file. To refresh trip data, use \"Refresh\" in the menu.", Toast.LENGTH_LONG).show();
}
} |
Partager