Advertisement
Guest User

Untitled

a guest
Jan 7th, 2013
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. class GetProductDetails extends AsyncTask<String, String, JSONObject> {
  2.  
  3. int text_size;
  4. SharedPreferences sharedPrefs;
  5. /**
  6. * Before starting background thread Show Progress Dialog
  7. * */
  8. @Override
  9. protected void onPreExecute() {
  10. super.onPreExecute();
  11. pDialog = new ProgressDialog(PM_article.this);
  12. pDialog.setMessage("Loading product details. Please wait...");
  13. pDialog.setIndeterminate(false);
  14. pDialog.setCancelable(true);
  15. pDialog.show();
  16.  
  17.  
  18. // product with this pid found
  19. // Edit Text
  20. art_title = (TextView) findViewById(R.id.display_title);
  21. art_author = (TextView) findViewById(R.id.display_author);
  22. art_publishtime = (TextView) findViewById(R.id.display_date);
  23. art_content = (TextView) findViewById(R.id.display_content);
  24. sharedPrefs = PreferenceManager
  25. .getDefaultSharedPreferences(context);
  26. // display product data in TextView
  27. text_size = Integer.parseInt(sharedPrefs.getString("prefFontSize", "1"));
  28.  
  29. }
  30.  
  31. /**
  32. * Getting product details in background thread
  33. * */
  34.  
  35. protected JSONObject doInBackground(String... args) {
  36. JSONObject json ;
  37. int success;
  38. try {
  39.  
  40. List<NameValuePair> params = new ArrayList<NameValuePair>();
  41. params.add(new BasicNameValuePair("id", id_pub));
  42.  
  43. JSONObject json = jParser.makeHttpRequest(url_load_article, "GET", params);
  44.  
  45.  
  46. } catch (JSONException e) {
  47. e.printStackTrace();
  48. }
  49.  
  50.  
  51.  
  52. return json;
  53. }
  54. /**
  55. * After completing background task Dismiss the progress dialog
  56. * **/
  57. protected void onPostExecute(JSONObject json) {
  58. // dismiss the dialog once got all details
  59. // json success tag
  60. success = json.getInt(TAG_SUCCESS);
  61. if (success == 1) {
  62. // successfully received product details
  63. JSONArray contentObj = json
  64. .getJSONArray(TAG_PRODUCT); // JSON Array
  65.  
  66. // get first product object from JSON Array
  67. JSONObject product = contentObj.getJSONObject(0);
  68.  
  69.  
  70. art_title.setText(product.getString(TAG_TITLE));
  71. art_title.setTextSize(TypedValue.COMPLEX_UNIT_SP, text_size+20);
  72. art_author.setText(product.getString(TAG_AUTHOR));
  73. art_author.setTextSize(TypedValue.COMPLEX_UNIT_SP, text_size+14);
  74. art_publishtime.setText(product.getString(TAG_PUBLISHTIME));
  75. art_publishtime.setTextSize(TypedValue.COMPLEX_UNIT_SP, text_size+14);
  76. art_content.setText(product.getString(TAG_CONTENT));
  77. art_content.setTextSize(TypedValue.COMPLEX_UNIT_SP, text_size+18);
  78.  
  79. }else{
  80. // product with pid not found
  81. }
  82. pDialog.dismiss();
  83. }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement