private class DownloadRouteTask extends AsyncTask<ArrayList<GPParameter>, String, GPJobParameter[]> { private Geoprocessor gpTask; private TextView textView; private String msg = ""; public DownloadRouteTask(Geoprocessor gpTask, TextView textView){ this.gpTask = gpTask; this.textView = textView; } @Override protected GPJobParameter[] doInBackground(ArrayList<GPParameter>... parameters) { GPJobParameter[] outParams = null; try { GPJobResource gpJobResource = gpTask.submitJob(parameters[0]); System.out.println("Polling thread is: " + Thread.currentThread().getName()); boolean done = false; while(!done) { if(isCancelled()){ break; } GPJobResource.JobStatus jobStatus = gpJobResource.getJobStatus(); switch (jobStatus) { case CANCELLED: msg = "The job has been cancelled based on the client's request. "; done = true; break; case CANCELLING: System.out.println("CANCELLING value on switch"); break; case DELETED: textView.setText("The job has been deleted. "); done = true; break; case DELETING: System.out.println("DELETING value on switch"); break; case EXECUTING: System.out.println("EXECUTING value on switch"); break; case FAILED: msg = "The job execution has failed because of invalid parameters or other geoprocessing failures. "; done = true; break; case NEW_JOB: System.out.println("NEW_JOB value on switch"); break; case SUBMITTED: System.out.println("SUBMITTED value on switch"); break; case SUCCEEDED: msg = "The job has completed successfully and the output results are available. "; outParams = gpJobResource.getOutputParameters(); done = true; break; case TIMED_OUT: msg = "The job execution has timed out. "; done = true; break; case WAITING: System.out.println("WAITING value on switch"); break; default: System.out.println("default value on switch"); } try { Thread.sleep(4000); } catch (InterruptedException e) { } } } catch(EsriSecurityException e){ if(e.getCode() == -10001){ msg = "There were no user with that name and password."; return null; } } catch (Exception e) { msg = e.getLocalizedMessage(); e.printStackTrace(); } return outParams; } @Override protected void onPostExecute(GPJobParameter[] result) { if(msg.length() > 0){ textView.setTextColor(getResources().getColor(R.color.text_dark_grey)); textView.setText(msg); } if(result != null) { if ( result.length > 0) { } else { textView.setTextColor(getResources().getColor(R.color.text_dark_grey)); textView.setText("There were no route with that id"); } } } // If the cancellation occurs, set the message informing so @Override protected void onCancelled() { textView.setTextColor(getResources().getColor(R.color.text_orange)); textView.setText("Job cancelled"); super.onCancelled(); } @Override public void onPreExecute(){ textView.setTextColor(getResources().getColor(R.color.text_dark_grey)); textView.setText("Fetching the route" ); } } |