Skip to content

Commit

Permalink
Made function API prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander James Wallar committed Jan 21, 2014
1 parent 2baa571 commit 5c64739
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app/Locabean/src/com/locaudio/api/Locaudio.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public AsyncGetRequest<SoundLocation[]> getSoundLocations(

@Override
public void runOnceReceivedResponse(SoundLocation[] response) {
callback.run(response);
callback.call(response);
}

};
Expand Down Expand Up @@ -52,7 +52,7 @@ public AsyncGetRequest<String[]> getNames(final Function<String[]> callback) {

@Override
public void runOnceReceivedResponse(String[] response) {
callback.run(response);
callback.call(response);
}

};
Expand Down Expand Up @@ -83,7 +83,7 @@ public AsyncPostRequest<NotifyResponse> notifyEvent(final NotifyForm event,

@Override
public void runOnceReceivedResponse(NotifyResponse response) {
callback.run(response);
callback.call(response);
}

};
Expand Down
9 changes: 6 additions & 3 deletions app/Locabean/src/com/locaudio/functional/Function.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.locaudio.functional;

public abstract class Function<T> {
public abstract void run(T input);

public abstract void body(T input);

public void call(T input) {
body(input);
}
@SuppressWarnings("rawtypes")
public static Function getEmptyFunction() {
return new Function() {

@Override
public void run(Object input) {
public void body(Object input) {
}

};
Expand Down
6 changes: 3 additions & 3 deletions app/Locabean/src/com/locaudio/functional/UIFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ public UIFunction(Activity activity) {
this.activity = activity;
}

public abstract void runUI(T input);
public abstract void body(T input);

public void run(final T input) {
public void call(final T input) {
this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
runUI(input);
body(input);
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion app/Locabean/src/com/locaudio/locabean/NodeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ public void onClick(View v) {
new UIFunction<NotifyResponse>(self) {

@Override
public void runUI(NotifyResponse nr) {
public void body(NotifyResponse nr) {
nameTextView.setText(nr.name);
confidenceTextView.setText("" + nr.confidence);
}

});
}
};
Expand Down

0 comments on commit 5c64739

Please sign in to comment.