From e556a75e78e4439e449b8c9ab52a5ac7b2a624ad Mon Sep 17 00:00:00 2001 From: satchit8 Date: Thu, 17 Nov 2016 13:42:38 +0000 Subject: [PATCH 1/2] Make config handle proxies of android.* classses --- src/clojure/neko/ui.clj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/clojure/neko/ui.clj b/src/clojure/neko/ui.clj index d98d9c9..f541cca 100644 --- a/src/clojure/neko/ui.clj +++ b/src/clojure/neko/ui.clj @@ -3,7 +3,8 @@ (:require [neko.ui.mapping :as kw] [neko.ui.traits :refer [apply-trait]] [neko.-utils :refer [keyword->setter reflect-setter - reflect-constructor]]) + reflect-constructor + closest-android-ancestor]]) (:import android.content.res.Configuration neko.App)) @@ -95,7 +96,8 @@ "Takes a widget and key-value pairs of attributes, and applies these attributes to the widget." [widget & {:as attributes}] - (apply-attributes (kw/keyword-by-classname (type widget)) + (apply-attributes (kw/keyword-by-classname (closest-android-ancestor + (class widget))) widget attributes {})) ;; ## Compatibility with Android XML UI facilities. From 0479ae1ab1d0491e062a484432cdf0134fa940a0 Mon Sep 17 00:00:00 2001 From: satchit8 Date: Sun, 20 Nov 2016 06:19:00 +0000 Subject: [PATCH 2/2] Enhance config test to consider proxy of container --- test/neko/t_ui.clj | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/neko/t_ui.clj b/test/neko/t_ui.clj index 001d220..f3bb702 100644 --- a/test/neko/t_ui.clj +++ b/test/neko/t_ui.clj @@ -6,6 +6,7 @@ (:import [android.widget Button LinearLayout TextView] android.content.pm.ActivityInfo android.view.View + android.widget.LinearLayout neko.App [org.robolectric Robolectric RuntimeEnvironment])) @@ -72,12 +73,20 @@ (is (= "hello" (.getText b)))))) (deftest config - (let [v (ui/make-ui RuntimeEnvironment/application [:button {:text "hello"}])] + (let [v (ui/make-ui RuntimeEnvironment/application [:button {:text "hello"}]) + ll (ui/make-ui RuntimeEnvironment/application + [:linear-layout {:custom-constructor + (fn [ctx] + (proxy [LinearLayout] [ctx])) + :orientation :vertical}])] (is (= View/VISIBLE (.getVisibility v))) (is (= "hello" (.getText v))) (ui/config v :text "updated" :visibility View/GONE) (is (= "updated" (.getText v))) - (is (= View/GONE (.getVisibility v))))) + (is (= View/GONE (.getVisibility v))) + (is (= LinearLayout/VERTICAL(.getOrientation ll))) + (ui/config ll :orientation :horizontal) + (is (= LinearLayout/HORIZONTAL (.getOrientation ll))))) (deftest inflate-layout (is (instance? TextView (ui/inflate-layout RuntimeEnvironment/application