/** * Helper function to set an alarm * * @param minutesFromNow * @throws UiObjectNotFoundException */ public void setAlarm(int minutesFromNow) throws UiObjectNotFoundException { UiObject setAlarm = new UiObject(new UiSelector().description("Alarms")); if (!setAlarm.exists()) setAlarm = new UiObject(new UiSelector().textStartsWith("Set alarm")); setAlarm.click(); UtilityFunctions uti = Controller.utilities; // let's add an alarm uti.clickByDescription("Add alarm"); // let's set the time // clickByText("Time"); Calendar c = Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("HHmm"); c.add(Calendar.MINUTE, 1); String now = format.format(c.getTime()); Log.i("ROOT", "alarm time: " + now); new UiObject( new UiSelector() .packageName(packageName) .className("android.widget.Button") .text("" + now.charAt(0))) .click(); new UiObject( new UiSelector() .packageName(packageName) .className("android.widget.Button") .text("" + now.charAt(1))) .click(); new UiObject( new UiSelector() .packageName(packageName) .className("android.widget.Button") .text("" + now.charAt(2))) .click(); new UiObject( new UiSelector() .packageName(packageName) .className("android.widget.Button") .text("" + now.charAt(3))) .click(); // clickByText("Ok"); // few confirmations to click thru UiObject doneButton = new UiObject(new UiSelector().text("Done")); UiObject okButton = new UiObject(new UiSelector().text("OK")); // working around some inconsistencies in phone vs tablet UI if (doneButton.exists()) { doneButton.click(); } else { okButton.click(); // let it fail if neither exists } // we're done. Let's return to home screen // clickByText("Done"); uti.goToHomeScreen(); }