Android Open Source - hackspacewidget Hackspace Status A P I






From Project

Back to project page hackspacewidget.

License

The source code is released under:

Apache License

If you think the Android project hackspacewidget 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 de.ring0.hackspace;
/*from  w  ww  .j a  va 2 s. c o m*/
import com.google.gson.Gson;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;


import de.ring0.hackspace.datatypes.Space;

public class HackspaceStatusAPI {
//  private final static String TAG = HackerSpaceStatusAPI.class.getSimpleName();
  private final static String VERSION = "0.1";
    private final static String CURRENT_API_VERSION = "0.13";
  
  private HttpClient client;
  private HttpGet get;
  
  public HackspaceStatusAPI(String url) {
    client = new DefaultHttpClient();
    get = new HttpGet(url);
    get.setHeader("Accept", "application/json");
    get.setHeader("User-Agent", String.format("Android Widget/%s", VERSION));
  }
  
  public Space run() throws ClientProtocolException, IOException {
    HttpEntity body;
    String line, content = "";
    Space ss = null;
    
    HttpResponse response = client.execute(get);

    if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK && (body = response.getEntity()) != null) {
      BufferedReader bir = new BufferedReader(new InputStreamReader(body.getContent()));
      while((line = bir.readLine()) != null) {
        content += line;
      }
      bir.close();

       Gson g = new Gson();
      ss = g.fromJson(content, Space.class);
      if(!ss.api.equals(CURRENT_API_VERSION)) {
        return ss;
      }
    }
    return ss;  
  }
}




Java Source Code List

de.ring0.hackspace.HackspaceInfoFragment.java
de.ring0.hackspace.HackspaceListFragment.java
de.ring0.hackspace.HackspaceStatusAPI.java
de.ring0.hackspace.HackspaceStatusProvider.java
de.ring0.hackspace.HackspaceViewActivity.java
de.ring0.hackspace.HackspaceWidgetConfig.java
de.ring0.hackspace.UpdateWidgetTask.java
de.ring0.hackspace.database.InternalHelper.java
de.ring0.hackspace.database.SpaceDataSource.java
de.ring0.hackspace.database.StatusDataSource.java
de.ring0.hackspace.datatypes.Space.java
de.ring0.hackspace.datatypes.field.SpaceCache.java
de.ring0.hackspace.datatypes.field.SpaceContact.java
de.ring0.hackspace.datatypes.field.SpaceEvent.java
de.ring0.hackspace.datatypes.field.SpaceFED.java
de.ring0.hackspace.datatypes.field.SpaceFeeds.java
de.ring0.hackspace.datatypes.field.SpaceIcon.java
de.ring0.hackspace.datatypes.field.SpaceKeymaster.java
de.ring0.hackspace.datatypes.field.SpaceLocation.java
de.ring0.hackspace.datatypes.field.SpaceRadioShow.java
de.ring0.hackspace.datatypes.field.SpaceSensors.java
de.ring0.hackspace.datatypes.field.SpaceState.java
de.ring0.hackspace.datatypes.sensors.AccountBalance.java
de.ring0.hackspace.datatypes.sensors.Barometer.java
de.ring0.hackspace.datatypes.sensors.BeverageSupply.java
de.ring0.hackspace.datatypes.sensors.DoorLocked.java
de.ring0.hackspace.datatypes.sensors.Humidity.java
de.ring0.hackspace.datatypes.sensors.NetworkConnections.java
de.ring0.hackspace.datatypes.sensors.PeopleNowPresent.java
de.ring0.hackspace.datatypes.sensors.PowerConsumption.java
de.ring0.hackspace.datatypes.sensors.Radiation.java
de.ring0.hackspace.datatypes.sensors.Sensor.java
de.ring0.hackspace.datatypes.sensors.Temperature.java
de.ring0.hackspace.datatypes.sensors.TotalMemberCount.java
de.ring0.hackspace.datatypes.sensors.Wind.java