Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.mobile_e_commerce.dummy;
- import java.io.File;
- import java.io.FileInputStream;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.ResourceBundle;
- import org.ksoap2.SoapEnvelope;
- import org.ksoap2.serialization.PropertyInfo;
- import org.ksoap2.serialization.SoapObject;
- import org.ksoap2.serialization.SoapSerializationEnvelope;
- import org.ksoap2.transport.HttpTransportSE;
- import android.app.Activity;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.os.AsyncTask;
- import android.util.Log;
- import android.view.View;
- import android.widget.ImageView;
- import com.example.mobile_e_commerce.ProductsListFragment;
- import com.example.mobile_e_commerce.R;
- /**
- * Helper class for providing sample content for user interfaces created by
- * Android template wizards.
- * <p>
- * TODO: Replace all uses of this class before publishing your app.
- */
- public class ProductInfo extends AsyncTask<Void,Void,Void> {
- /**
- * An array of sample (dummy) items.
- */
- private static final ResourceBundle rb = ResourceBundle.getBundle("com.example.mobile_e_commerce.webserviceurl");
- private final static String NAMESPACE = rb.getString("WSDLTargetNamespace");
- private final static String SoapURL = rb.getString("SoapAddress");
- private final static String SOAP_ACTION = rb.getString("SoapAction");
- private final static String METHOD_NAME = rb.getString("OperationName");
- private final String SOAP_ACTION2 = rb.getString("SoapAction2");
- private final String METHOD_NAME2 = rb.getString("OperationName2");
- private final String SOAP_ACTION3 = rb.getString("SoapAction3");
- private final String METHOD_NAME3 = rb.getString("OperationName3");
- private final String SOAP_ACTION4 = rb.getString("SoapAction4");
- private final String METHOD_NAME4 = rb.getString("OperationName4");
- private final String SOAP_ACTION5 = rb.getString("SoapAction5");
- private final static String METHOD_NAME5 = rb.getString("OperationName5");
- private final static String SOAP_ACTION6 = rb.getString("SoapAction6");//image location
- private final static String METHOD_NAME6 = rb.getString("OperationName6");//image location
- private final static String SOAP_ACTION7 = rb.getString("SoapAction7");
- private final static String METHOD_NAME7 = rb.getString("OperationName7");
- Activity activity = new Activity();
- public static List<ProductItem> ITEMS = new ArrayList<ProductItem>();
- /**
- * A map of sample (dummy) items, by ID.
- */
- // private File file = new File(Integer.toString(R.drawable.search));
- private String[] valuePass = new String[100];
- private String imgData= "";
- private String imgLoc;
- private String Product = "Samsung Galaxy S4 Zoom";
- private int i;
- PropertyInfo pi = new PropertyInfo();
- // ImageView imageView = (ImageView)Activity.findViewById(R.id.productImgDisplay);
- private int n =0;
- PropertyInfo getInfo = new PropertyInfo();
- // private int number = 0;
- @Override
- protected Void doInBackground(Void... arg0) {
- try
- {
- //get the no of the product
- Object response2 = null;
- SoapObject request2 = new SoapObject(NAMESPACE,METHOD_NAME5);
- SoapSerializationEnvelope envelope2 = new SoapSerializationEnvelope(SoapEnvelope.VER11);
- envelope2.dotNet = true;
- envelope2.setOutputSoapObject(request2);
- HttpTransportSE httpTransport2 = new HttpTransportSE(SoapURL);
- httpTransport2.call(SOAP_ACTION5, envelope2);
- response2 = envelope2.getResponse();
- i = Integer.parseInt(response2.toString());
- //get the imageData of the product
- pi.setName("name");
- pi.setValue("Samsung Galaxy S III 16GB");
- pi.setType(String.class);
- Object response3 = null;
- SoapObject request3 = new SoapObject(NAMESPACE,METHOD_NAME7);
- SoapSerializationEnvelope envelope3 = new SoapSerializationEnvelope(SoapEnvelope.VER11);
- request3.addProperty(pi);
- envelope3.dotNet = true;
- envelope3.setOutputSoapObject(request3);
- HttpTransportSE httpTransport3 = new HttpTransportSE(SoapURL);
- httpTransport3.call(SOAP_ACTION7, envelope3);
- response3 = envelope3.getResponse();
- imgData = response3.toString();
- //Log.e("Image Data: ", imgData);
- ImageLoader(imgData);
- try {
- //get the name of the product
- Object response = null;
- while(n < i) {
- SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
- SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
- envelope.dotNet = true;
- request.addProperty("number", n);
- envelope.setOutputSoapObject(request);
- HttpTransportSE httpTransport = new HttpTransportSE(SoapURL);
- httpTransport.call(SOAP_ACTION, envelope);
- response = envelope.getResponse();
- //imageurl equal to byte type image data,will add to WS later
- valuePass[n] = response.toString();
- addItem(new ProductItem(Integer.toString(i), valuePass[n]));
- n++;
- }
- } catch (Exception exception) {
- exception.printStackTrace();
- Log.e("Apps Error", exception.toString());
- } catch (Exception exception) {
- exception.printStackTrace();
- Log.e("Apps Error", exception.toString());
- }
- return null;
- }
- public void setExecution(ProductsListFragment exec)//to initialize the variable using class
- {
- this.execute();
- }
- public static Map<String, ProductItem> ITEM_MAP = new HashMap<String, ProductItem>();
- /*static {
- // // Add 3 sample items.
- addItem(new ProductItem("1", "Item 1"));
- addItem(new ProductItem("2", "Item 2"));
- addItem(new ProductItem("3", "Item 3"));
- }*/
- private static void addItem(ProductItem item) {
- //Log.e("Item added second", item.toString());
- ITEMS.add(item);
- ITEM_MAP.put(item.id, item);
- }
- public Byte imageToByte()//generate byte type image
- {
- File file = new File("C:\Users\SYNLAPUSR004\workspace\Mobile_E-Commerce\res\drawable-hdpi\s3.jpg");
- Byte[] c = null;
- int i = 0;
- try {
- FileInputStream fis = new FileInputStream(file);
- while ((fis.read()) != -1) {
- c[i] = (byte) fis.read();
- i++;
- fis.close();
- return c[i];
- }
- } catch (Exception ee) {
- }
- return null;
- }
- public void ImageLoader(String imageData)
- {
- Bitmap bm;
- // byte[] bitmapdata = null;
- ImageView P_Image = (ImageView)activity.findViewById(R.id.productImgDisplay);
- // activity = ProductsListFragment;
- /*
- byte[] fileBytes = imageData.getBytes();
- // Log.e("Image Data", (imageData.getBytes()).toString());
- // Log.e("Image Location", imageLoc);
- File file = new File(Environment.getExternalStorageDirectory() + File.separator + "s3.jpg");
- //File file = new File(,"s3.jpg");
- Log.e("File Directory", Environment.getExternalStorageDirectory().toString());
- try
- {
- // file.createNewFile();
- OutputStream targetFile=
- new FileOutputStream(
- file);
- targetFile.write(fileBytes);
- targetFile.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }*/
- // bm = BitmapFactory.decodeResource(getResources(), id);
- bm = BitmapFactory.decodeByteArray(imageData.getBytes(), 0, imageData.getBytes().length);
- Log.e("Image Ori Data: ", bm.toString());
- P_Image.setImageBitmap(bm);
- P_Image.setVisibility(View.VISIBLE);
- }
- /**
- * A dummy item representing a piece of content.
- */
- public static class ProductItem {//Instantiation of variable
- public String id;
- public String content;
- public ProductItem(String id, String content) {
- this.id = id;
- this.content = content;
- }
- @Override
- public String toString() {
- return content;
- }
- }
- }
- 04-14 10:58:15.471: W/System.err(5939): java.lang.NullPointerException
- 04-14 10:58:15.471: W/System.err(5939): at android.app.Activity.findViewById(Activity.java:1794)
- 04-14 10:58:15.471: W/System.err(5939): at com.example.mobile_e_commerce.dummy.ProductInfo.ImageLoader(ProductInfo.java:224)
- 04-14 10:58:15.471: W/System.err(5939): at com.example.mobile_e_commerce.dummy.ProductInfo.doInBackground(ProductInfo.java:119)
- 04-14 10:58:15.471: W/System.err(5939): at com.example.mobile_e_commerce.dummy.ProductInfo.doInBackground(ProductInfo.java:1)
- 04-14 10:58:15.471: W/System.err(5939): at android.os.AsyncTask$2.call(AsyncTask.java:264)
- 04-14 10:58:15.471: W/System.err(5939): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
- 04-14 10:58:15.471: W/System.err(5939): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
- 04-14 10:58:15.471: W/System.err(5939): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
- 04-14 10:58:15.471: W/System.err(5939): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
- 04-14 10:58:15.471: W/System.err(5939): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
- 04-14 10:58:15.471: W/System.err(5939): at java.lang.Thread.run(Thread.java:856)
- 04-14 10:58:15.471: E/Apps Error(5939): java.lang.NullPointerException
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement