public void setCurrentSearch(Search newSearch, String result) { Action.Type actionType = null; yesNoSearch.setActive(true); yesNoSearch.setPotentialField(result); yesNoSearch.setResponse("Did you mean " + result + "?"); // Set parent search for re-routing after user response if (Search.getCurrentSearch() != null && Search.getCurrentSearch() != yesNoSearch) { yesNoSearch.setParentSearch(Search.getCurrentSearch()); Log.d(TAG, "parent search of yesNo search set to " + Search.getCurrentSearch().getName()); } if (newSearch == binSearch) { actionType = Action.Type.LOG_BIN_ITEM; } else if (newSearch == typeSearch) { actionType = Action.Type.LOG_LITTER_TYPE; } else if (newSearch == brandSearch) { actionType = Action.Type.LOG_LITTER_BRAND; } else if (newSearch == yesNoSearch) { yesNoSearch.setYesAction(mActionHandler.getCurrentAction().getActionType()); yesNoSearch.setNoAction(getActionFromSearch(yesNoSearch.getParentSearch())); } if (actionType != null) { mActionHandler.getCurrentAction().setActionType(actionType); } Search.setCurrentSearch(newSearch); }
// Deal with unexpected results private String processUnexpectedResult(String result) { String toastText = ""; // Cancel item and start again if needed if (result.equals("cancel") || result.equals("council") || result.equals("Council") || result.equals("cancer") || result.equals("pencil")) { mOutingManager.speak("item cancelled"); setCurrentSearch(brandSearch, result); mBin = null; mLitter = null; return null; } for (LocalEntity menuItem : menuSearch.getSearchObjects()) { if (menuItem.getSearchTerms().contains(result)) { setCurrentSearchByString(menuItem.getName()); return null; } } if (!Search.getCurrentSearch().getName().equals("menu")) { toastText = "I haven't heard of " + result + ". Should I log it as other?"; // log current item as 'other' and record the result yesNoSearch.setActive(true); yesNoSearch.setResponse(toastText); yesNoSearch.setPotentialOtherField(result); if (Search.getCurrentSearch().equals(brandSearch)) { mActionHandler.getCurrentAction().setActionType(Action.Type.LOG_OTHER_BRAND); } if (Search.getCurrentSearch().equals(typeSearch)) { mActionHandler.getCurrentAction().setActionType(Action.Type.LOG_OTHER_LITTER_TYPE); } if (Search.getCurrentSearch().equals(binSearch)) { mActionHandler.getCurrentAction().setActionType(Action.Type.LOG_OTHER_BIN_TYPE); } Log.d(TAG, "result at other: " + result); Log.d(TAG, "yesnosearch potentialotherfield set to " + yesNoSearch.getPotentialOtherField()); Log.d(TAG, "currentSearch at unexpected result = " + Search.getCurrentSearch().getName()); setCurrentSearch(yesNoSearch, ""); return toastText; } else { setCurrentSearch(brandSearch, result); return null; } }
private void processExpectedResult(String result) { // If result is affirmative then assume it is in response to a confirmation question and // perform pending action associated with current search if (yesNoSearch.getYesTerms().getSearchTerms().contains(result)) { yesNoSearch.setActive(false); Log.d(TAG, "user answered yes"); performAction(yesNoSearch.getYesAction(), result); return; } // If result is negative, assume it is in response to a confirmation as above if (yesNoSearch.getNoTerms().getSearchTerms().contains(result)) { yesNoSearch.setActive(false); Log.d(TAG, "user answered no"); Log.d(TAG, "current no action = " + yesNoSearch.getNoAction()); performAction(yesNoSearch.getNoAction(), result); return; } // Otherwise set next search, update UI and start listening for next input mActionHandler.setActionPerformed(false); setCurrentSearchByString(result); Log.d(TAG, "new current search before UI update = " + Search.getCurrentSearch().getName()); }