public class NotificationGeoFenceTab extends Activity
{
// String Str = new String("2011-10-24 10:09:52.0");
String Str, Str2;
public static NotificationGeoFenceTab INSTANCE;
ListView GFlist;
// public ArrayList<GeoFenceData> items = new ArrayList<GeoFenceData>();
private static int caseNumber;
private static String xmlData;
private static String loginId;
public ArrayList<NotificationGeoFenceData> geoitem = new ArrayList<NotificationGeoFenceData>();
// int weAreAt = 0;
public NotificationGeoFenceData notificationgeofenceData;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("Activity Name", "NotificationGeoFenceTab extends Activity");
setContentView(R.layout.notification_geofence_alert1);
INSTANCE = this;
GFlist = (ListView) findViewById(R.id.geofencelist);
GFlist.setAdapter(new GeoFenceListAdapter(getApplicationContext(),
R.layout.notification_listdata1_geofencedata,geoitem));
caseNumber = 6;
xmlData = "<zoltit.avts.bean.VehicleInputParam><timeIntervel>"
+ ApplicationVariables.user_minutes
+ "</timeIntervel></zoltit.avts.bean.VehicleInputParam>";
loginId = ApplicationVariables.loginId;
SoapService service = new SoapService();
try {
String result = service.SoapService(caseNumber, xmlData, loginId);
parseAlertsData(result);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void parseAlertsData(String xmlRecord) throws Exception {
// TODO Auto-generated method stub
DocumentBuilder db = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xmlRecord));
Document doc = db.parse(is);
NodeList violation_list = doc.getElementsByTagName("violationlist");
for (int i = 0; i < violation_list.getLength(); i++) {
Element element = (Element) violation_list.item(i);
NodeList geofence_info = doc.getElementsByTagName("geofenceInfo");
for (int j = 0; j < geofence_info.getLength(); j++) {
NodeList geofence_list = element
.getElementsByTagName("geofencelist");
// Toast.makeText(getApplicationContext(),
// "geofenceLength" + geofence_list.getLength(),
// Toast.LENGTH_LONG).show();
for (int k = 0; k < geofence_list.getLength(); k++) {
NodeList vehicle = element
.getElementsByTagName("registratioNo");
NodeList actual_location = element
.getElementsByTagName("actualLocation");
NodeList original_location = element
.getElementsByTagName("originalLocation");
NodeList date = element.getElementsByTagName("date");
Element el_vehicle = (Element) vehicle.item(k);
Element el_actualLocation = (Element) actual_location
.item(k);
Element el_originalLocation = (Element) original_location
.item(k);
Element el_date = (Element) date.item(k);
Str = new String(getCharacterDataFromElement(el_date));
Str2 = new String(
getCharacterDataFromElement(el_originalLocation));
String s[] = Str2.split(",");
String originalLocation = s[0] + "," + s[1];
String date1 = Str.substring(0, 9);
String time1 = Str.substring(10, 16); // Str.length() - 1);
notificationgeofenceData = new NotificationGeoFenceData(getCharacterDataFromElement(el_vehicle),
getCharacterDataFromElement(el_actualLocation),
originalLocation, date1, time1);
geoitem.add(notificationgeofenceData);
}
}
}
}
private String getCharacterDataFromElement(Element e) {
Node child = e.getFirstChild();
if (child instanceof CharacterData) {
CharacterData cd = (CharacterData) child;
return cd.getData();
}
return "";
}
private class GeoFenceListAdapter extends ArrayAdapter<NotificationGeoFenceData> {
private ArrayList<NotificationGeoFenceData> GeoFenceDetails;
private Context mContext;
public GeoFenceListAdapter(Context context, int textViewResourceId,
ArrayList<NotificationGeoFenceData> objects) {
super(context, textViewResourceId, objects);
GeoFenceDetails = objects;
mContext = context;
}
@Override
public int getCount() {
return geoitem.size();
}
@Override
public NotificationGeoFenceData getItem(int position) {
return GeoFenceDetails.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vl = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vl.inflate(R.layout.notification_listdata1_geofencedata, null);
}
TextView actualtxt = (TextView) v.findViewById(R.id.txtactual_id);
TextView orinigaltxt = (TextView) v.findViewById(R.id.txtoriginal_id);
TextView datetxt = (TextView) v.findViewById(R.id.txtdate_id);
TextView timetxt = (TextView) v.findViewById(R.id.txttime_id);
TextView vechiletxt= (TextView) v.findViewById(R.id.txtvechile_id);
NotificationGeoFenceData temp = geoitem.get(position);
actualtxt.setText(temp.Actual);
orinigaltxt.setText(temp.Original);
datetxt.setText(temp.Date);
timetxt.setText(temp.Time);
vechiletxt.setText(temp.vehicle);
return v;
}
}
}
No comments:
Post a Comment