Guest User

Untitled

a guest
Apr 22nd, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.36 KB | None | 0 0
  1. public void postMyData(final frmListServiceCalls parent, final ArrayList<NameValuePair> postParameters){
  2.        
  3.         DATASyncStatus = DATA_PROCESSING;
  4.        
  5.         Log.i("PremSCNBlob","postMyData() : processing : Blob.getSCN()=`"+ getSCN()+"` DATASyncStatus=`"+DATASyncStatus+"`");
  6.         /***
  7.          * initialise with id because SECURITY was added in the CONSTRUCTOR
  8.          */                
  9.         final String getstring = "http://home.pfsp.co.uk:8043/app/uploadData.php?id=" + getId();
  10.  
  11.         /*****
  12.          * send Images and content / add fields where neccesary
  13.          */
  14.         if (isPendArrivalDateTime()){
  15.             postParameters.add(new BasicNameValuePair("arrival_datetime", URLEncoder.encode(getArrivalDateTime())));
  16.         }
  17.         if (isPendTravelTime()){
  18.             postParameters.add(new BasicNameValuePair("traveltime", URLEncoder.encode(getTravelTime())));
  19.         }
  20.         if (isPendCompletedDateTime()){
  21.             postParameters.add(new BasicNameValuePair("completed_datetime", URLEncoder.encode(getCompletedDateTime())));
  22.         }
  23.         if (isPendWorksRequired()){
  24.             postParameters.add(new BasicNameValuePair("works_required", URLEncoder.encode(getWorksRequired())));
  25.         }
  26.         if (isPendWorksConducted()){
  27.             postParameters.add(new BasicNameValuePair("works_conducted", URLEncoder.encode(getWorksConducted())));
  28.         }
  29.         if (isPendPartsUsed()){
  30.             postParameters.add(new BasicNameValuePair("parts_used", URLEncoder.encode(getPartsUsed())));
  31.         }
  32.         if (isPendWorkClosedStatusCode()){
  33.             postParameters.add(new BasicNameValuePair("work_closed_status_code", URLEncoder.encode(getWorkClosedStatusCode())));
  34.         }
  35.         if (isPendCallStatus()){
  36.             postParameters.add(new BasicNameValuePair("call_status_code", URLEncoder.encode(getCallStatus())));
  37.         }                              
  38.        
  39.         /***
  40.          * normal async "get"
  41.          *               - -  - - -  - -
  42.          *               - -  - - -  - -
  43.          *               - -  - - -  - -    - - P O S T     A L L     E X C E P T     I M A G E
  44.          *               - -  - - -  - -
  45.          */
  46.         final class GetUserHttpTask extends AsyncTask<String/* Param */, Boolean /* Progress */, String /* Result */> {
  47.            
  48.             /*************
  49.              * busy dialog
  50.              */
  51.             private final ProgressDialog dialog = new ProgressDialog(parent);
  52.  
  53.             protected void onPreExecute() {
  54.                 this.dialog.setMessage("DataPosting");
  55.                 this.dialog.setCancelable(false);
  56.                 this.dialog.show();
  57.             }          
  58.            
  59.            
  60.             /*************
  61.              * attempt to post
  62.              */
  63.             @Override
  64.             protected String doInBackground(String... params) {
  65.                 publishProgress(true);
  66.                 Log.i("PremSCNBlob","postMyData() : GetUserHttpTask.doInBackground()=`"+ getSCN()+"` DATASyncStatus=`"+DATASyncStatus+"`");                    
  67.                
  68.                 try {
  69.                     Log.i("PremSCNBlob","postMyData() : GetUserHttpTask.doInBackground()(try)");
  70.                     String targetUrl = getstring;                                                
  71.                     String response = Include_CustomHttpClient.executeHttpPost(targetUrl, postParameters);
  72.                     Log.i("PremSCNBlob","postMyData() : GetUserHttpTask.doInBackground()(try)(response=`"+response+"`)");
  73.                     return response;
  74.                 } catch (Exception e) {
  75.                     DATASyncStatus = DATA_FAILED;
  76.                     Log.e("PremSCNBlob","postMyData() : GetUserHttpTask.doInBackground()(catch)\n" + e.getStackTrace());  
  77.                     return "";
  78.                 }
  79.             } // </ doInBackground()>
  80.            
  81.             /***
  82.              * on complete
  83.              */
  84.             @Override
  85.             protected void onPostExecute(String result) {
  86.                 publishProgress(false);
  87.                 Log.i("PremSCNBlob","postMyData() : GetUserHttpTask.onPostExecute()(start)=`"+ getSCN()+"` DATASyncStatus=`"+DATASyncStatus+"`");
  88.                
  89.                 try{
  90.                     if (result.length()>3 && result.substring(0,3).equals("OK:")){                        
  91.                         /***
  92.                          * ALL OK
  93.                          */                                                
  94.                             //lovely
  95.                             DATASyncStatus = DATA_COMPLETED_OK;
  96.                             Log.i("PremSCNBlob","postMyData() : GetUserHttpTask.onPostExecute()(done)=`"+ getSCN()+"` DATASyncStatus=`"+DATASyncStatus+"`");
  97.                            
  98.                     }
  99.                     else{
  100.                         /**
  101.                          * error: disconnect
  102.                          */
  103.                             //stall the !refresh!
  104.                             httpDataFailedMessage = result;
  105.                             DATASyncStatus = DATA_FAILED;
  106.                             Log.i("PremSCNBlob","postMyData() : GetUserHttpTask.onPostExecute()(fail)=`"+ getSCN()+"` DATASyncStatus=`"+DATASyncStatus+"`");
  107.                     }
  108.  
  109.                     if (this.dialog.isShowing()) {
  110.                         this.dialog.dismiss();
  111.                     }
  112.                    
  113.                 } catch (Exception e) {
  114.                     DATASyncStatus = DATA_FAILED;
  115.                     Log.e("PremSCNBlob","postMyData() : GetUserHttpTask.onPostExecute()(catch)\n" + e.getStackTrace());  
  116.                 }
  117.             } // </ onPostExecute()>
  118.         }
  119.         try{
  120.             parent.runOnUiThread(new Runnable() {  
  121.                 @Override
  122.                 public void run() {
  123.                     new GetUserHttpTask().execute();
  124.                 }
  125.             });
  126.         }
  127.         catch (Exception e){
  128.             DATASyncStatus = DATA_FAILED;
  129.             Log.e("PremSCNBlob","postMyData() : GetUserHttpTask().execute()(catch)\n" + e.getStackTrace());  
  130.         }
  131.     }
Advertisement
Add Comment
Please, Sign In to add comment