Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.72 KB | None | 0 0
  1. package com.example.mobile_e_commerce.dummy;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. import java.util.ResourceBundle;
  10.  
  11. import org.ksoap2.SoapEnvelope;
  12. import org.ksoap2.serialization.PropertyInfo;
  13. import org.ksoap2.serialization.SoapObject;
  14. import org.ksoap2.serialization.SoapSerializationEnvelope;
  15. import org.ksoap2.transport.HttpTransportSE;
  16.  
  17. import android.app.Activity;
  18. import android.graphics.Bitmap;
  19. import android.graphics.BitmapFactory;
  20. import android.os.AsyncTask;
  21. import android.util.Log;
  22. import android.view.View;
  23. import android.widget.ImageView;
  24.  
  25. import com.example.mobile_e_commerce.ProductsListFragment;
  26. import com.example.mobile_e_commerce.R;
  27.  
  28. /**
  29. * Helper class for providing sample content for user interfaces created by
  30. * Android template wizards.
  31. * <p>
  32. * TODO: Replace all uses of this class before publishing your app.
  33. */
  34. public class ProductInfo extends AsyncTask<Void,Void,Void> {
  35.  
  36. /**
  37. * An array of sample (dummy) items.
  38. */
  39. private static final ResourceBundle rb = ResourceBundle.getBundle("com.example.mobile_e_commerce.webserviceurl");
  40.  
  41. private final static String NAMESPACE = rb.getString("WSDLTargetNamespace");
  42. private final static String SoapURL = rb.getString("SoapAddress");
  43. private final static String SOAP_ACTION = rb.getString("SoapAction");
  44. private final static String METHOD_NAME = rb.getString("OperationName");
  45. private final String SOAP_ACTION2 = rb.getString("SoapAction2");
  46. private final String METHOD_NAME2 = rb.getString("OperationName2");
  47. private final String SOAP_ACTION3 = rb.getString("SoapAction3");
  48. private final String METHOD_NAME3 = rb.getString("OperationName3");
  49. private final String SOAP_ACTION4 = rb.getString("SoapAction4");
  50. private final String METHOD_NAME4 = rb.getString("OperationName4");
  51. private final String SOAP_ACTION5 = rb.getString("SoapAction5");
  52. private final static String METHOD_NAME5 = rb.getString("OperationName5");
  53. private final static String SOAP_ACTION6 = rb.getString("SoapAction6");//image location
  54. private final static String METHOD_NAME6 = rb.getString("OperationName6");//image location
  55. private final static String SOAP_ACTION7 = rb.getString("SoapAction7");
  56. private final static String METHOD_NAME7 = rb.getString("OperationName7");
  57.  
  58. Activity activity = new Activity();
  59.  
  60. public static List<ProductItem> ITEMS = new ArrayList<ProductItem>();
  61.  
  62. /**
  63. * A map of sample (dummy) items, by ID.
  64. */
  65.  
  66.  
  67. // private File file = new File(Integer.toString(R.drawable.search));
  68.  
  69. private String[] valuePass = new String[100];
  70. private String imgData= "";
  71. private String imgLoc;
  72. private String Product = "Samsung Galaxy S4 Zoom";
  73. private int i;
  74. PropertyInfo pi = new PropertyInfo();
  75. // ImageView imageView = (ImageView)Activity.findViewById(R.id.productImgDisplay);
  76.  
  77. private int n =0;
  78. PropertyInfo getInfo = new PropertyInfo();
  79. // private int number = 0;
  80.  
  81.  
  82.  
  83. @Override
  84. protected Void doInBackground(Void... arg0) {
  85. try
  86. {
  87. //get the no of the product
  88. Object response2 = null;
  89. SoapObject request2 = new SoapObject(NAMESPACE,METHOD_NAME5);
  90. SoapSerializationEnvelope envelope2 = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  91.  
  92. envelope2.dotNet = true;
  93.  
  94. envelope2.setOutputSoapObject(request2);
  95.  
  96. HttpTransportSE httpTransport2 = new HttpTransportSE(SoapURL);
  97.  
  98. httpTransport2.call(SOAP_ACTION5, envelope2);
  99. response2 = envelope2.getResponse();
  100.  
  101. i = Integer.parseInt(response2.toString());
  102.  
  103.  
  104. //get the imageData of the product
  105. pi.setName("name");
  106. pi.setValue("Samsung Galaxy S III 16GB");
  107. pi.setType(String.class);
  108. Object response3 = null;
  109. SoapObject request3 = new SoapObject(NAMESPACE,METHOD_NAME7);
  110. SoapSerializationEnvelope envelope3 = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  111. request3.addProperty(pi);
  112. envelope3.dotNet = true;
  113.  
  114. envelope3.setOutputSoapObject(request3);
  115.  
  116. HttpTransportSE httpTransport3 = new HttpTransportSE(SoapURL);
  117. httpTransport3.call(SOAP_ACTION7, envelope3);
  118. response3 = envelope3.getResponse();
  119. imgData = response3.toString();
  120. //Log.e("Image Data: ", imgData);
  121.  
  122. ImageLoader(imgData);
  123. try {
  124. //get the name of the product
  125. Object response = null;
  126.  
  127. while(n < i) {
  128. SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
  129. SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  130. envelope.dotNet = true;
  131. request.addProperty("number", n);
  132. envelope.setOutputSoapObject(request);
  133. HttpTransportSE httpTransport = new HttpTransportSE(SoapURL);
  134. httpTransport.call(SOAP_ACTION, envelope);
  135. response = envelope.getResponse();
  136.  
  137. //imageurl equal to byte type image data,will add to WS later
  138.  
  139. valuePass[n] = response.toString();
  140. addItem(new ProductItem(Integer.toString(i), valuePass[n]));
  141.  
  142. n++;
  143. }
  144. } catch (Exception exception) {
  145. exception.printStackTrace();
  146. Log.e("Apps Error", exception.toString());
  147. } catch (Exception exception) {
  148. exception.printStackTrace();
  149. Log.e("Apps Error", exception.toString());
  150. }
  151. return null;
  152.  
  153. }
  154.  
  155. public void setExecution(ProductsListFragment exec)//to initialize the variable using class
  156. {
  157. this.execute();
  158. }
  159.  
  160. public static Map<String, ProductItem> ITEM_MAP = new HashMap<String, ProductItem>();
  161. /*static {
  162. // // Add 3 sample items.
  163. addItem(new ProductItem("1", "Item 1"));
  164. addItem(new ProductItem("2", "Item 2"));
  165. addItem(new ProductItem("3", "Item 3"));
  166. }*/
  167.  
  168. private static void addItem(ProductItem item) {
  169. //Log.e("Item added second", item.toString());
  170. ITEMS.add(item);
  171. ITEM_MAP.put(item.id, item);
  172. }
  173.  
  174. public Byte imageToByte()//generate byte type image
  175. {
  176. File file = new File("C:\Users\SYNLAPUSR004\workspace\Mobile_E-Commerce\res\drawable-hdpi\s3.jpg");
  177. Byte[] c = null;
  178. int i = 0;
  179. try {
  180. FileInputStream fis = new FileInputStream(file);
  181.  
  182. while ((fis.read()) != -1) {
  183. c[i] = (byte) fis.read();
  184. i++;
  185. fis.close();
  186. return c[i];
  187. }
  188. } catch (Exception ee) {
  189. }
  190. return null;
  191. }
  192.  
  193. public void ImageLoader(String imageData)
  194. {
  195. Bitmap bm;
  196. // byte[] bitmapdata = null;
  197. ImageView P_Image = (ImageView)activity.findViewById(R.id.productImgDisplay);
  198. // activity = ProductsListFragment;
  199.  
  200. /*
  201. byte[] fileBytes = imageData.getBytes();
  202. // Log.e("Image Data", (imageData.getBytes()).toString());
  203. // Log.e("Image Location", imageLoc);
  204. File file = new File(Environment.getExternalStorageDirectory() + File.separator + "s3.jpg");
  205. //File file = new File(,"s3.jpg");
  206. Log.e("File Directory", Environment.getExternalStorageDirectory().toString());
  207. try
  208. {
  209. // file.createNewFile();
  210. OutputStream targetFile=
  211. new FileOutputStream(
  212. file);
  213. targetFile.write(fileBytes);
  214. targetFile.close();
  215.  
  216.  
  217. }
  218. catch (Exception e)
  219. {
  220. e.printStackTrace();
  221. }*/
  222. // bm = BitmapFactory.decodeResource(getResources(), id);
  223. bm = BitmapFactory.decodeByteArray(imageData.getBytes(), 0, imageData.getBytes().length);
  224. Log.e("Image Ori Data: ", bm.toString());
  225. P_Image.setImageBitmap(bm);
  226. P_Image.setVisibility(View.VISIBLE);
  227.  
  228.  
  229.  
  230. }
  231.  
  232. /**
  233. * A dummy item representing a piece of content.
  234. */
  235. public static class ProductItem {//Instantiation of variable
  236. public String id;
  237. public String content;
  238.  
  239. public ProductItem(String id, String content) {
  240. this.id = id;
  241. this.content = content;
  242. }
  243.  
  244. @Override
  245. public String toString() {
  246. return content;
  247. }
  248. }
  249.  
  250. }
  251.  
  252. 04-14 10:58:15.471: W/System.err(5939): java.lang.NullPointerException
  253. 04-14 10:58:15.471: W/System.err(5939): at android.app.Activity.findViewById(Activity.java:1794)
  254. 04-14 10:58:15.471: W/System.err(5939): at com.example.mobile_e_commerce.dummy.ProductInfo.ImageLoader(ProductInfo.java:224)
  255. 04-14 10:58:15.471: W/System.err(5939): at com.example.mobile_e_commerce.dummy.ProductInfo.doInBackground(ProductInfo.java:119)
  256. 04-14 10:58:15.471: W/System.err(5939): at com.example.mobile_e_commerce.dummy.ProductInfo.doInBackground(ProductInfo.java:1)
  257. 04-14 10:58:15.471: W/System.err(5939): at android.os.AsyncTask$2.call(AsyncTask.java:264)
  258. 04-14 10:58:15.471: W/System.err(5939): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  259. 04-14 10:58:15.471: W/System.err(5939): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
  260. 04-14 10:58:15.471: W/System.err(5939): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
  261. 04-14 10:58:15.471: W/System.err(5939): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
  262. 04-14 10:58:15.471: W/System.err(5939): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
  263. 04-14 10:58:15.471: W/System.err(5939): at java.lang.Thread.run(Thread.java:856)
  264. 04-14 10:58:15.471: E/Apps Error(5939): java.lang.NullPointerException
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement