Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.newsapp;
- import java.util.Vector;
- import org.ksoap2.SoapEnvelope;
- import org.ksoap2.serialization.SoapObject;
- import org.ksoap2.serialization.SoapSerializationEnvelope;
- import org.ksoap2.transport.HttpTransport;
- import org.xmlpull.v1.XmlPullParserException;
- import com.newsapp.ui.TableList;
- import net.rim.device.api.ui.UiApplication;
- import net.rim.device.api.system.DeviceInfo;
- import net.rim.device.api.ui.container.MainScreen;
- public final class ScreenApp extends MainScreen {
- private Vector _data = null;
- public ScreenApp() {
- setTitle("News App");
- this.startLoad();
- }
- private void startLoad() {
- String WSD_URL = "http://www.domain.com/service.asmx";
- String WSD_NAMESPACE = "http://www.domain.com/service";
- String WSD_ACTION = "http://www.domain.com/service/GetList";
- SoapObject soap = new SoapObject(WSD_NAMESPACE, "GetList");
- int _PIN = DeviceInfo.getDeviceId();
- String PIN = "" + _PIN;
- soap.addProperty("deviceId", PIN);
- soap.addProperty("deviceType", "B");
- SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
- envelope.dotNet = true;
- envelope.encodingStyle = SoapSerializationEnvelope.XSD;
- envelope.setOutputSoapObject(soap);
- HttpTransport ht = new HttpTransport(WSD_URL);
- ht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- try {
- ht.call(WSD_ACTION, envelope);
- if(envelope.getResponse() != null) {
- SoapObject resp = (SoapObject)envelope.getResponse();
- this.initInterface(resp);
- }
- } catch (XmlPullParserException ex) {
- } catch (Exception e) {
- Item item = new Item("Problem with connection", "Please close app and try again", "");
- this._data = new Vector(1);
- this._data.addElement(item);
- TableList list = new TableList(this._data);
- list.setSize(this._data.size());
- add(list);
- }
- }
- private void initInterface(SoapObject response) {
- int count = response.getPropertyCount();
- this._data = new Vector(count);
- for(int i=0; i<count; i++) {
- String line = response.getProperty(i).toString();
- String title = this.getAttributeElement(line, "Title");
- String description = this.getAttributeElement(line, "Description");
- String link = this.getAttributeElement(line, "Link");
- Item item = new Item(title, description, link);
- this._data.addElement(item);
- }
- TableList list = new TableList(this._data);
- list.setSize(this._data.size());
- add(list);
- }
- private String getAttributeElement(String line, String elem) {
- String attr = line.substring(line.indexOf(elem + "=") + (elem.length() + 1), line.indexOf(";", line.indexOf(elem + "=")));
- return attr;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement