Android Open Source - havadurumu Xml Data Handler






From Project

Back to project page havadurumu.

License

The source code is released under:

Apache License

If you think the Android project havadurumu listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.tr.kodgraf.havadurumusamp;
/*from w w w  . j a  v a2 s .  c  o  m*/
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.util.Log;

public class XmlDataHandler extends DefaultHandler {

  public String day, city, country, conditionText, 
    todayLowTemp, todayHighTemp, tomorrowLowTemp, tomorrowHighTemp, 
    currentTemp, imageURL = null;
  
  @Override
  public void startElement(String uri, String localName, String qName,
      Attributes attributes) throws SAXException {
    
    if(localName.equals("location")) {
      city = attributes.getValue("city");
      country = attributes.getValue("country");
    } else if( localName.equals("condition")) {
      conditionText = attributes.getValue("text");
      currentTemp = attributes.getValue("temp");
      imageURL = "http://l.yimg.com/a/i/us/we/52/"+ attributes.getValue("code") +".gif";
      day = attributes.getValue("date").substring(0, 3);
    } else if( localName.equals("forecast")){
      if(attributes.getValue("day").equalsIgnoreCase(day)) {
        todayLowTemp = attributes.getValue("low");
        todayHighTemp = attributes.getValue("high");
      } else {
        tomorrowLowTemp = attributes.getValue("low");
        tomorrowHighTemp = attributes.getValue("high");
      }
    }
    
  }
  
  public String getResult() {
    return "?ehir: " + this.city + " - lke: " + this.country + "\n" 
        + "S?cakl?k: " + this.currentTemp + " - Durum: " + this.conditionText + "\n"
        + "Bugn En D?k S?cakl?k: " + this.todayLowTemp + "\n"
        + "Bugn En Yksek S?cakl?k: " + this.todayHighTemp + "\n"
        + "Yar?n En D?k S?cakl?k: " + this.tomorrowLowTemp + "\n"
        + "Yar?n En Yksek S?cakl?k: " + this.tomorrowHighTemp + "\n";
  }
}




Java Source Code List

com.tr.kodgraf.havadurumusamp.GeoPlanetDataHandler.java
com.tr.kodgraf.havadurumusamp.HavaDurumu.java
com.tr.kodgraf.havadurumusamp.XmlDataHandler.java