 
 (ns neko.resource
   "Provides utilities to resolve application resources."
-  (:require [clojure.string :as string])
-  (:use [neko.init.options :only [*package-name*]]
-        [neko.context :only [context]]))
+  (:require [clojure.string :as string]
+            [neko.context :as context])
+  (:use [neko.init.options :only [*package-name*]])
+  (:import android.content.Context android.graphics.drawable.Drawable))
+
+;; ## Runtime resource resolution
 
 (def package-name *package-name*)
 
-(defn- resource-symbol
-  "Returns a symbol that represents a resource field specified by type
-  and name keywords. If `name` is not a keyword, just returns it back."
-  [type name]
-  (if (not (keyword? name))
-    name
-    (let [package (or (namespace name) package-name)
-          type    (clojure.core/name type)
-          name    (-> (clojure.core/name name)
-                      (string/replace \- \_)
-                      (string/replace \. \_))]
-      (symbol (str package ".R$" type "/" name)))))
+(defn- kw-to-res-name
+  "Takes the name of the keyword and turns all hyphens and periods to
+  underscores."
+  [kw]
+  (-> (name kw)
+      (string/replace \- \_)
+      (string/replace \. \_)))
 
-(defmacro get-resource
+(defn get-resource
   "Resolves the resource ID of a given type with the given name.  For example,
   to refer to what in Java would be R.string.my_string, you can use:
 
-    (get-resource :string :my_string)
+    `(get-resource :string :my-string)`
 
   The type should be a keyword corresponding to a resource type such as
   :layout, :attr, or :id.


  If the name argument is an integer, it is assumed to be a valid resource ID
  and will be returned as is without any processing."
  [type name]
  {:pre  [(keyword? type)]}
  (resource-symbol type name))

(defmacro get-id
  "Finds the ID for the XML item with the given name.  This is simply a
  convenient way of calling (get-resource :id name)."
  [name]
  (resource-symbol :id name))

(defmacro get-string
  "Gets the localized string with the given ID or name from the context.
  The name will be resolved using get-resource.

  If additional arguments are supplied, the string will be interpreted as a
  format and the arguments will be applied to the format."
  ([name]
     `(.getString context ~(resource-symbol :string name)))
  ([name & args]
     `(.getString context ~(resource-symbol :string name) (to-array ~args))))

(defmacro get-layout
  "Finds the resource ID for the layout with the given name.  This is simply a
  convenient way of calling (get-resource context :layout name)."
  [name]
  (resource-symbol :layout name))

  can be used to access the resources from the platform.  For example, the
  equivalent to android.R.layout.simple_list_item_1 is:

    `(get-resource :layout :android/simple-list-item-1)`

  The name portion of the name argument will be converted to a string and any
  hyphens or periods will be transformed to underscores.  Note that hyphens are
