Source:
<code>public void enableSetDateAndSetTime() throws Exception { Instrumentation instrumentation = testFramework.getInstrumentation(); UiDevice device = testFramework.getDevice(); AppLauncher.launch(instrumentation, "Settings"); UiScrollable itemList = new UiScrollable( new UiSelector().resourceIdMatches(Res.SETTINGS_LIST_CONTAINER_RES)); itemList.setAsVerticalList(); itemList.scrollIntoView(new UiSelector().textContains("Date & time")); device.findObject(new UiSelector().text("Date & time")).click(); UiObject2 switchWidget = UiAutomatorPlus.findObjectByRelative( instrumentation, By.clazz("android.widget.Switch"), By.text("Automatic date & time"), By.clazz("android.widget.ListView")); if (!switchWidget.isChecked()) { switchWidget.click(); } <START> assertTrue((switchWidget).isChecked()); <END> assertTrue(!device.findObject(new UiSelector().text("Set date")).isEnabled()); assertTrue(!device.findObject(new UiSelector().text("Set time")).isEnabled()); switchWidget.click(); assertTrue(device.findObject(new UiSelector().text("Set date")).isEnabled()); assertTrue(device.findObject(new UiSelector().text("Set time")).isEnabled()); device.findObject(new UiSelector().text("Set date")).click(); assertTrue(device.findObject( new UiSelector().resourceId(Res.ANDROID_DATE_PICKER_HEADER_RES)).exists()); device.findObject(new UiSelector().textContains("CANCEL")).click(); device.findObject(new UiSelector().text("Set time")).click(); assertTrue(device.findObject( new UiSelector().resourceId(Res.ANDROID_TIME_HEADER_RES)).exists()); device.findObject(new UiSelector().textContains("CANCEL")).click(); }</code><technical_language>Remove this line. necessary</technical_language>

Target:
public void enableSetDateAndSetTime() throws Exception { Instrumentation instrumentation = testFramework.getInstrumentation(); UiDevice device = testFramework.getDevice(); AppLauncher.launch(instrumentation, "Settings"); UiScrollable itemList = new UiScrollable( new UiSelector().resourceIdMatches(Res.SETTINGS_LIST_CONTAINER_RES)); itemList.setAsVerticalList(); itemList.scrollIntoView(new UiSelector().textContains("Date & time")); device.findObject(new UiSelector().text("Date & time")).click(); UiObject2 switchWidget = UiAutomatorPlus.findObjectByRelative( instrumentation, By.clazz("android.widget.Switch"), By.text("Automatic date & time"), By.clazz("android.widget.ListView")); if (!switchWidget.isChecked()) { switchWidget.click(); } assertTrue(!device.findObject(new UiSelector().text("Set date")).isEnabled()); assertTrue(!device.findObject(new UiSelector().text("Set time")).isEnabled()); switchWidget.click(); assertTrue(device.findObject(new UiSelector().text("Set date")).isEnabled()); assertTrue(device.findObject(new UiSelector().text("Set time")).isEnabled()); device.findObject(new UiSelector().text("Set date")).click(); assertTrue(device.findObject( new UiSelector().resourceId(Res.ANDROID_DATE_PICKER_HEADER_RES)).exists()); device.findObject(new UiSelector().textContains("CANCEL")).click(); device.findObject(new UiSelector().text("Set time")).click(); assertTrue(device.findObject( new UiSelector().resourceId(Res.ANDROID_TIME_HEADER_RES)).exists()); device.findObject(new UiSelector().textContains("CANCEL")).click(); }