Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class GetProductDetails extends AsyncTask<String, String, JSONObject> {
- int text_size;
- SharedPreferences sharedPrefs;
- /**
- * Before starting background thread Show Progress Dialog
- * */
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- pDialog = new ProgressDialog(PM_article.this);
- pDialog.setMessage("Loading product details. Please wait...");
- pDialog.setIndeterminate(false);
- pDialog.setCancelable(true);
- pDialog.show();
- // product with this pid found
- // Edit Text
- art_title = (TextView) findViewById(R.id.display_title);
- art_author = (TextView) findViewById(R.id.display_author);
- art_publishtime = (TextView) findViewById(R.id.display_date);
- art_content = (TextView) findViewById(R.id.display_content);
- sharedPrefs = PreferenceManager
- .getDefaultSharedPreferences(context);
- // display product data in TextView
- text_size = Integer.parseInt(sharedPrefs.getString("prefFontSize", "1"));
- }
- /**
- * Getting product details in background thread
- * */
- protected JSONObject doInBackground(String... args) {
- JSONObject json ;
- int success;
- try {
- List<NameValuePair> params = new ArrayList<NameValuePair>();
- params.add(new BasicNameValuePair("id", id_pub));
- JSONObject json = jParser.makeHttpRequest(url_load_article, "GET", params);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return json;
- }
- /**
- * After completing background task Dismiss the progress dialog
- * **/
- protected void onPostExecute(JSONObject json) {
- // dismiss the dialog once got all details
- // json success tag
- success = json.getInt(TAG_SUCCESS);
- if (success == 1) {
- // successfully received product details
- JSONArray contentObj = json
- .getJSONArray(TAG_PRODUCT); // JSON Array
- // get first product object from JSON Array
- JSONObject product = contentObj.getJSONObject(0);
- art_title.setText(product.getString(TAG_TITLE));
- art_title.setTextSize(TypedValue.COMPLEX_UNIT_SP, text_size+20);
- art_author.setText(product.getString(TAG_AUTHOR));
- art_author.setTextSize(TypedValue.COMPLEX_UNIT_SP, text_size+14);
- art_publishtime.setText(product.getString(TAG_PUBLISHTIME));
- art_publishtime.setTextSize(TypedValue.COMPLEX_UNIT_SP, text_size+14);
- art_content.setText(product.getString(TAG_CONTENT));
- art_content.setTextSize(TypedValue.COMPLEX_UNIT_SP, text_size+18);
- }else{
- // product with pid not found
- }
- pDialog.dismiss();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement