diff options
author | Andy Doan <andy.doan@linaro.org> | 2011-09-19 14:43:49 -0500 |
---|---|---|
committer | Andy Doan <doanac@gmail.com> | 2011-09-19 14:43:49 -0500 |
commit | 1800bf18743a5566f515608f6f7693beb89918f2 (patch) | |
tree | 0cdb1d2a5995bb6027f2139fdfc2c106cbad456d /src/org/linaro/connect/JSONLayoutItem.java | |
download | LinaroConnect-1800bf18743a5566f515608f6f7693beb89918f2.tar.gz |
initial commit
this includes a very simple way to display items that have
URL's associated with them
Diffstat (limited to 'src/org/linaro/connect/JSONLayoutItem.java')
-rw-r--r-- | src/org/linaro/connect/JSONLayoutItem.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/org/linaro/connect/JSONLayoutItem.java b/src/org/linaro/connect/JSONLayoutItem.java new file mode 100644 index 0000000..8f0703d --- /dev/null +++ b/src/org/linaro/connect/JSONLayoutItem.java @@ -0,0 +1,64 @@ +package org.linaro.connect; + +import java.util.HashMap; + +import org.json.JSONObject; +import org.linaro.connect.handler.IJSONHandler; +import org.linaro.connect.handler.JSONUrlHandler; + +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +class JSONLayoutItem { + + private final JSONObject mJSO; + + private final static HashMap<String, IJSONHandler> HANDLERS; + + static { + HANDLERS = new HashMap<String, IJSONHandler>(); + HANDLERS.put("URL", new JSONUrlHandler()); + } + + public JSONLayoutItem(JSONObject jso) { + mJSO = jso; + } + + private static String getField(JSONObject jso, String name) { + try { + return jso.getString(name); + } + catch(Throwable t) { + Log.e(LinaroConnectActivity.TAG, "error getting '"+name+"'", t); + } + return null; + } + + public String getLabel() { + return getField(mJSO, "label"); + } + + public String getHandler() { + return getField(mJSO, "handler"); + } + + public String getData() { + return getField(mJSO, "data"); + } + + public Intent getIntent(Context ctx) { + String key = getHandler(); + String data = getData(); + IJSONHandler handler = HANDLERS.get(key); + return handler.getIntent(ctx, data); + } + + @Override + public String toString() { + String lbl = getLabel(); + if (lbl == null) + lbl = mJSO.toString(); + return lbl; + } +} |