private void setSelectedButtonHighlight(boolean highlighted) { mCallback.setEqualButtonColor(highlighted); //Don't color if "More" button was selected if (mUnitType.getCurrUnitButtonPos() < mNumConvButtons){ int currButtonPos = mUnitType.getCurrUnitButtonPos(); //if no button is selected, return if (currButtonPos == -1) return; // this fixes a bug when currency is selected and app leaves, and we // reload, currency is still selected and this is a null pointer if (currButtonPos >= mConvButton.size()) return; //set the current button to highlighted or not mConvButton.get(currButtonPos).setSelected(highlighted); } } }
private void tryConvert(int buttonPos) { //Clear color and arrows from previously selected convert buttons clearButtonSelection(); //Set select unit, also this will potentially call convert if we already have a selected unit boolean requestConvert = mUnitType.selectUnit(buttonPos); Calculator calc = Calculator.getCalculator(getActivity()); //unit previously selected, we pressed another, do a convert if (requestConvert){ calc.convertFromTo(mUnitType.getPrevUnit(), mUnitType.getCurrUnit()); clearButtonSelection(); } //unit not previously selected, now select one else if (mUnitType.isUnitSelected()){ // clear out solved flag calc.setSolved(false); //if expression was blank, add a highlighted "1" if (calc.isExpressionEmpty()){ //add in a 1 for user's convenience calc.parseKeyPressed("1"); //highlight it calc.setSelection(0, calc.toString().length()); } colorSelectedButton(); } //always update screen to add/remove unit from expression mCallback.updateScreen(true); }