[AC-2206] Android touchEnabled=false throws java error
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Duplicate |
Resolution Date | 2013-12-23T02:27:50.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Alloy |
Labels | n/a |
Reporter | Andrew Greenstreet |
Assignee | Ritu Agrawal |
Created | 2013-12-17T15:06:13.000+0000 |
Updated | 2016-03-08T07:41:12.000+0000 |
Description
In an alloy view, setting touchEnabled='false' on any view type (view, label, etc) will throw
[ERROR] : TiApplication: (main) [98,98] Sending event: exception on thread: main msg:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gstreetmedia.threetwotest/org.appcelerator.titanium.TiActivity}: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean; Titanium 3.2.0,2013/12/16 06:43,2a93aca
[ERROR] : TiApplication: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gstreetmedia.threetwotest/org.appcelerator.titanium.TiActivity}: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
[ERROR] : TiApplication: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
[ERROR] : TiApplication: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
[ERROR] : TiApplication: at android.app.ActivityThread.access$700(ActivityThread.java:135)
[ERROR] : TiApplication: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
[ERROR] : TiApplication: at android.os.Handler.dispatchMessage(Handler.java:102)
[ERROR] : TiApplication: at android.os.Looper.loop(Looper.java:137)
[ERROR] : TiApplication: at android.app.ActivityThread.main(ActivityThread.java:4998)
[ERROR] : TiApplication: at java.lang.reflect.Method.invokeNative(Native Method)
[ERROR] : TiApplication: at java.lang.reflect.Method.invoke(Method.java:515)
[ERROR] : TiApplication: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
[ERROR] : TiApplication: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
[ERROR] : TiApplication: at dalvik.system.NativeStart.main(Native Method)
[ERROR] : TiApplication: Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
[ERROR] : TiApplication: at org.appcelerator.titanium.view.TiUIView.registerForTouch(TiUIView.java:1455)
[ERROR] : TiApplication: at org.appcelerator.titanium.view.TiUIView.registerForTouch(TiUIView.java:1270)
[ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:474)
[ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:451)
[ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:489)
[ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:473)
[ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:451)
[ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.handleAdd(TiViewProxy.java:568)
[ERROR] : TiApplication: at org.appcelerator.titanium.proxy.TiViewProxy.add(TiViewProxy.java:546)
[ERROR] : TiApplication: at ti.modules.titanium.ui.WindowProxy.windowCreated(WindowProxy.java:303)
[ERROR] : TiApplication: at org.appcelerator.titanium.TiActivityWindows.windowCreated(TiActivityWindows.java:32)
[ERROR] : TiApplication: at org.appcelerator.titanium.TiBaseActivity.windowCreated(TiBaseActivity.java:451)
[ERROR] : TiApplication: at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:527)
[ERROR] : TiApplication: at org.appcelerator.titanium.TiActivity.onCreate(TiActivity.java:18)
[ERROR] : TiApplication: at android.app.Activity.performCreate(Activity.java:5243)
[ERROR] : TiApplication: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
[ERROR] : TiApplication: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
[ERROR] : TiApplication: ... 11 more
index.xml is as follows
Suggestion for fixing this is to update TiUIView.java with protected void registerForTouch(final View touchable) { if (touchable == null) { return; } boolean clickable = true; if (proxy.hasProperty(TiC.PROPERTY_TOUCH_ENABLED)) { Object obj = proxy.getProperty(TiC.PROPERTY_TOUCH_ENABLED); if (obj.getClass().equals(String.class)) { clickable = obj.equals("false") ? false : true; } else if (obj.getClass().equals(Boolean.class)) { clickable = (Boolean) obj; } } if (clickable) { registerTouchEvents(touchable); // Previously, we used the single tap handling above to fire our click event. It doesn't // work: a single tap is not the same as a click. A click can be held for a while before // lifting the finger; a single-tap is only generated from a quick tap (which will also cause // a click.) We wanted to do it in single-tap handling presumably because the singletap // listener gets a MotionEvent, which gives us the information we want to provide to our // users in our click event, whereas Android's standard OnClickListener does _not_ contain // that info. However, an "up" seems to always occur before the click listener gets invoked, // so we store the last up event's x,y coordinates (see onTouch above) and use them here. // Note: AdapterView throws an exception if you try to put a click listener on it. doSetClickable(touchable); } else { touchable.setSoundEffectsEnabled(false); } }
Thanks for reporting this issue and suggesting a solution. This issue is already covered by TIMOB-16063 and being actively worked upon by the engineering team. Please watch TIMOB-16063 for further updates.