-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexander James Wallar
committed
Jan 20, 2014
1 parent
02e8172
commit 4080336
Showing
13 changed files
with
273 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.locaudio.api; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class Location { | ||
@SerializedName("position") | ||
public Point position; | ||
|
||
@SerializedName("confidence") | ||
public float confidence; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package com.locaudio.api; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import org.apache.http.client.ClientProtocolException; | ||
|
||
import android.os.AsyncTask; | ||
|
||
import com.locaudio.net.Requests; | ||
|
||
public class Locaudio extends Requests { | ||
private static final String NAMES_ROUTE = "names"; | ||
private static final String NOTIFY_ROUTE = "notify"; | ||
private static final String LOCATIONS_ROUTE = "locations"; | ||
|
||
public Locaudio(String ipAddress, int port) { | ||
super(ipAddress, port); | ||
} | ||
|
||
public Location[] getSoundLocations(final String soundName) { | ||
|
||
AsyncTask<Requests, Integer, Location[]> task = new AsyncTask<Requests, Integer, Location[]>() { | ||
|
||
@Override | ||
protected Location[] doInBackground(Requests... reqs) { | ||
try { | ||
return reqs[0].get(Location[].class, LOCATIONS_ROUTE, | ||
soundName); | ||
} catch (ClientProtocolException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
}; | ||
|
||
try { | ||
task.execute(this); | ||
return task.get(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} catch (ExecutionException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
public String[] getNames() throws ClientProtocolException, IOException { | ||
AsyncTask<Requests, Integer, String[]> task = new AsyncTask<Requests, Integer, String[]>() { | ||
|
||
@Override | ||
protected String[] doInBackground(Requests... reqs) { | ||
try { | ||
return reqs[0].get(String[].class, NAMES_ROUTE); | ||
} catch (ClientProtocolException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
}; | ||
|
||
try { | ||
task.execute(this); | ||
return task.get(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} catch (ExecutionException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
public NotifyResponse notifyEvent(final NotifyForm event) | ||
throws ClientProtocolException, IOException { | ||
AsyncTask<Requests, Integer, NotifyResponse> task = new AsyncTask<Requests, Integer, NotifyResponse>() { | ||
|
||
@Override | ||
protected NotifyResponse doInBackground(Requests... reqs) { | ||
try { | ||
return reqs[0].post(NotifyResponse.class, event.toMap(), NOTIFY_ROUTE); | ||
} catch (ClientProtocolException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
}; | ||
|
||
try { | ||
task.execute(this); | ||
return task.get(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} catch (ExecutionException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.locaudio.api; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class NotifyForm { | ||
|
||
private float x; | ||
private float y; | ||
private float soundPressureLevel; | ||
private float timestamp; | ||
private byte[] fingerprint; | ||
|
||
public NotifyForm() { | ||
|
||
} | ||
|
||
public NotifyForm(float x, float y, float soundPressureLevel, | ||
float timestamp, byte[] fingerprint) { | ||
this.x = x; | ||
this.y = y; | ||
this.soundPressureLevel = soundPressureLevel; | ||
this.timestamp = timestamp; | ||
this.fingerprint = fingerprint; | ||
} | ||
|
||
public Map<String, ?> toMap() { | ||
Map<String, Object> map = new HashMap<String, Object>(); | ||
map.put("x", this.x); | ||
map.put("y", this.y); | ||
map.put("spl", this.soundPressureLevel); | ||
map.put("timestamp", this.timestamp); | ||
map.put("fingerprint", this.fingerprint); | ||
return map; | ||
} | ||
|
||
public NotifyForm setX(float x) { | ||
this.x = x; | ||
return this; | ||
} | ||
|
||
public NotifyForm setY(float y) { | ||
this.y = y; | ||
return this; | ||
} | ||
|
||
public NotifyForm setSoundPressureLevel(float soundPressureLevel) { | ||
this.soundPressureLevel = soundPressureLevel; | ||
return this; | ||
} | ||
|
||
public NotifyForm setTimestamp(float timestamp) { | ||
this.timestamp = timestamp; | ||
return this; | ||
} | ||
|
||
public NotifyForm setFingerprint(byte[] fingerprint) { | ||
this.fingerprint = fingerprint; | ||
return this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.locaudio.api; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class NotifyResponse { | ||
@SerializedName("error") | ||
public int error; | ||
|
||
@SerializedName("message") | ||
public String message; | ||
|
||
@SerializedName("name") | ||
public String name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.locaudio.api; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class Point { | ||
|
||
@SerializedName("x") | ||
public float x; | ||
|
||
@SerializedName("y") | ||
public float y; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.