@@ -335,29 +335,30 @@ private static void appendNode(
335335 node .getBoundsInScreen (bounds );
336336 xml .append ("<node" );
337337 appendAttribute (xml , "index" , Integer .toString (nodeIndex ));
338- appendAttribute (xml , "text" , node .getText ());
339- appendAttribute (xml , "resource-id" , node .getViewIdResourceName ());
338+ appendNonEmptyAttribute (xml , "text" , node .getText ());
339+ appendNonEmptyAttribute (xml , "resource-id" , node .getViewIdResourceName ());
340340 appendAttribute (xml , "class" , node .getClassName ());
341- appendAttribute (xml , "package" , node .getPackageName ());
342- appendAttribute (xml , "content-desc" , node .getContentDescription ());
343- appendAttribute (xml , "checkable" , Boolean .toString (node .isCheckable ()));
344- appendAttribute (xml , "checked" , Boolean .toString (node .isChecked ()));
345- appendAttribute (xml , "clickable" , Boolean .toString (node .isClickable ()));
341+ appendNonEmptyAttribute (xml , "package" , node .getPackageName ());
342+ appendNonEmptyAttribute (xml , "content-desc" , node .getContentDescription ());
343+ appendTrueAttribute (xml , "clickable" , node .isClickable ());
346344 appendAttribute (xml , "enabled" , Boolean .toString (node .isEnabled ()));
347- appendAttribute (xml , "focusable" , Boolean .toString (node .isFocusable ()));
348- appendAttribute (xml , "focused" , Boolean .toString (node .isFocused ()));
349- appendAttribute (xml , "scrollable" , Boolean .toString (node .isScrollable ()));
350- appendAttribute (
351- xml ,
352- "can-scroll-forward" ,
353- Boolean .toString (hasAccessibilityAction (node , AccessibilityAction .ACTION_SCROLL_FORWARD )));
354- appendAttribute (
355- xml ,
356- "can-scroll-backward" ,
357- Boolean .toString (hasAccessibilityAction (node , AccessibilityAction .ACTION_SCROLL_BACKWARD )));
358- appendAttribute (xml , "long-clickable" , Boolean .toString (node .isLongClickable ()));
359- appendAttribute (xml , "password" , Boolean .toString (node .isPassword ()));
360- appendAttribute (xml , "selected" , Boolean .toString (node .isSelected ()));
345+ appendTrueAttribute (xml , "focusable" , node .isFocusable ());
346+ appendTrueAttribute (xml , "focused" , node .isFocused ());
347+ boolean scrollable = node .isScrollable ();
348+ if (scrollable ) {
349+ appendAttribute (xml , "scrollable" , "true" );
350+ appendAttribute (
351+ xml ,
352+ "can-scroll-forward" ,
353+ Boolean .toString (
354+ hasAccessibilityAction (node , AccessibilityAction .ACTION_SCROLL_FORWARD )));
355+ appendAttribute (
356+ xml ,
357+ "can-scroll-backward" ,
358+ Boolean .toString (
359+ hasAccessibilityAction (node , AccessibilityAction .ACTION_SCROLL_BACKWARD )));
360+ }
361+ appendTrueAttribute (xml , "password" , node .isPassword ());
361362 appendAttribute (
362363 xml ,
363364 "bounds" ,
@@ -397,6 +398,19 @@ private static void appendNode(
397398 xml .append ("</node>" );
398399 }
399400
401+ private static void appendNonEmptyAttribute (StringBuilder xml , String name , CharSequence value ) {
402+ if (value == null || value .length () == 0 ) {
403+ return ;
404+ }
405+ appendAttribute (xml , name , value );
406+ }
407+
408+ private static void appendTrueAttribute (StringBuilder xml , String name , boolean value ) {
409+ if (value ) {
410+ appendAttribute (xml , name , "true" );
411+ }
412+ }
413+
400414 private static void appendAttribute (StringBuilder xml , String name , CharSequence value ) {
401415 String stringValue = value == null ? "" : value .toString ();
402416 xml .append (' ' );
0 commit comments