From 5c64739bd99edc28d613419c103ff3bbdaa1f502 Mon Sep 17 00:00:00 2001 From: Alexander James Wallar Date: Tue, 21 Jan 2014 03:23:41 -0500 Subject: [PATCH] Made function API prettier --- app/Locabean/src/com/locaudio/api/Locaudio.java | 6 +++--- app/Locabean/src/com/locaudio/functional/Function.java | 9 ++++++--- app/Locabean/src/com/locaudio/functional/UIFunction.java | 6 +++--- app/Locabean/src/com/locaudio/locabean/NodeActivity.java | 3 ++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/Locabean/src/com/locaudio/api/Locaudio.java b/app/Locabean/src/com/locaudio/api/Locaudio.java index 17d3cd2..825f2e9 100644 --- a/app/Locabean/src/com/locaudio/api/Locaudio.java +++ b/app/Locabean/src/com/locaudio/api/Locaudio.java @@ -20,7 +20,7 @@ public AsyncGetRequest getSoundLocations( @Override public void runOnceReceivedResponse(SoundLocation[] response) { - callback.run(response); + callback.call(response); } }; @@ -52,7 +52,7 @@ public AsyncGetRequest getNames(final Function callback) { @Override public void runOnceReceivedResponse(String[] response) { - callback.run(response); + callback.call(response); } }; @@ -83,7 +83,7 @@ public AsyncPostRequest notifyEvent(final NotifyForm event, @Override public void runOnceReceivedResponse(NotifyResponse response) { - callback.run(response); + callback.call(response); } }; diff --git a/app/Locabean/src/com/locaudio/functional/Function.java b/app/Locabean/src/com/locaudio/functional/Function.java index 427876f..3e42c38 100644 --- a/app/Locabean/src/com/locaudio/functional/Function.java +++ b/app/Locabean/src/com/locaudio/functional/Function.java @@ -1,14 +1,17 @@ package com.locaudio.functional; public abstract class Function { - 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) { } }; diff --git a/app/Locabean/src/com/locaudio/functional/UIFunction.java b/app/Locabean/src/com/locaudio/functional/UIFunction.java index d0cf9bd..503de9b 100644 --- a/app/Locabean/src/com/locaudio/functional/UIFunction.java +++ b/app/Locabean/src/com/locaudio/functional/UIFunction.java @@ -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); } }); } diff --git a/app/Locabean/src/com/locaudio/locabean/NodeActivity.java b/app/Locabean/src/com/locaudio/locabean/NodeActivity.java index 0ca900c..292e0a1 100644 --- a/app/Locabean/src/com/locaudio/locabean/NodeActivity.java +++ b/app/Locabean/src/com/locaudio/locabean/NodeActivity.java @@ -139,10 +139,11 @@ public void onClick(View v) { new UIFunction(self) { @Override - public void runUI(NotifyResponse nr) { + public void body(NotifyResponse nr) { nameTextView.setText(nr.name); confidenceTextView.setText("" + nr.confidence); } + }); } };