Android Open Source - android-home-auto Data Manager






From Project

Back to project page android-home-auto.

License

The source code is released under:

Apache License

If you think the Android project android-home-auto 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 app.davols.home.data;
//from  w  w w  .j a  v  a  2 s .c om
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;

public class DataManager {

  public DataManager() {

  }

  public List<HomeUnit> getHomeUnits() throws JsonParseException, IOException {
    return getHomeUnits(new URL("http://192.168.0.14/"));
  }
  
  private List<HomeUnit> getHomeUnits(URL url) throws JsonParseException, IOException{
    List<HomeUnit> mList = Lists.newArrayList();
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory f = new JsonFactory();
  
    JsonParser jp = f.createParser(url);
    // advance stream to START_ARRAY first:
    jp.nextToken();
    
    // and then each time, advance to opening START_OBJECT
    while (jp.nextToken() == JsonToken.START_OBJECT) {
      HomeUnit foobar = mapper.readValue(jp, HomeUnit.class);
      // process
      // after binding, stream points to closing END_OBJECT
      mList.add(foobar);
    }
    MyLog.d("DataManager","list:"+mList.size());
    return mList;
  }
  public List<HomeUnit> setStatus(int id,int status) throws JsonParseException, MalformedURLException, IOException {

    //http://192.168.0.14/set=0&value=255
     return getHomeUnits(new URL("http://192.168.0.14/set="+id+"&value="+status));
    
  }
}




Java Source Code List

app.davols.home.MainActivity.java
app.davols.home.data.DataManager.java
app.davols.home.data.HomeUnit.java
app.davols.home.data.MyLog.java