/** * Grabs newest data from Calculator, updates the main display * * @param updateResult whether or not to update result */ public void updateScreen(boolean updateResult) { //no instant scroll for previous expression updateScreen(updateResult, false); //see if colored convert button should be not colored (if backspace or //clear were pressed, or if expression solved) if (!mCalc.isUnitSelected() && mUnitTypeViewPager != null) clearUnitSelection(mUnitTypeViewPager.getCurrentItem()); }
/** * Called when any non convert key is pressed * * @param keyPressed ASCII representation of the key pressed ("1", "=" "*", etc) */ public void numButtonPressed(String keyPressed) { //pass button value to CalcActivity to pass to calc Calculator.CalculatorResultFlags flags = mCalc.parseKeyPressed(keyPressed); if (flags.createDiffUnitDialog){ new AlertDialog.Builder(this) .setMessage(getText(R.string.click_another_unit)) .setPositiveButton(android.R.string.ok, null) //null cancels dialog .show(); } //update the result list and do it with the normal scroll (not fast) updateScreen(flags.performedSolve); }
/** * Perform a full reset of the calculator. Clears expression, history, * preferences, and resets the calculator to original state. */ public void resetCalculator() { mCalc.resetCalc(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = preferences.edit(); editor.clear(); editor.apply(); setupUnitTypePager(); updateScreen(true); ViewUtils.toastCentered("Calculator reset", mAppContext); }
/** * Clears the history, updates the screen, and toasts the user */ public void clearHistory() { mCalc.clearResultList(); updateScreen(true); ViewUtils.toastCentered("History cleared", mAppContext); }
private void setUnitViewVisibility(UnitVisibility uv) { final LinearLayout mUnitContain = (LinearLayout) findViewById(R.id.unit_container); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){ if (uv == UnitVisibility.HIDDEN || mCalc.getUnitTypeSize() == 0 || (uv == UnitVisibility.TOGGLE && mUnitContain.getVisibility() == LinearLayout.VISIBLE)) mUnitContain.setVisibility(LinearLayout.GONE); else { mUnitContain.setVisibility(LinearLayout.VISIBLE); //update the screen to move result list up updateScreen(true, true); } } }
@Override public void onPageSelected(int pos) { // clear unit selection from current Unit Type before switching mCalc.getCurrUnitType().clearUnitSelection(); //update the calc with current UnitType selection mCalc.setCurrentUnitTypePos(pos); //if we just switched to a dynamic unit, attempt an update if (mCalc.getCurrUnitType().containsDynamicUnits()) mCalc.refreshAllDynamicUnits(false); //clear selected unit from adjacent convert key fragment so you //a bit of it int currUnitTypePos = mUnitTypeViewPager.getCurrentItem(); clearUnitSelection(currUnitTypePos - 1); clearUnitSelection(currUnitTypePos); clearUnitSelection(currUnitTypePos + 1); mCalc.getCurrUnitType().clearUnitSelection(); //if this change in UnitType was result of unit-ed result selection, // select that unit if (unitPosToSelectAfterScroll != -1){ ConvKeysFragment frag = getConvKeyFrag(mUnitTypeViewPager.getCurrentItem()); if (frag != null) frag.selectUnitAtUnitArrayPos(unitPosToSelectAfterScroll); unitPosToSelectAfterScroll = -1; } //clear out the unit in expression if it's now cleared updateScreen(true); //move the cursor to the right end (helps usability a bit) mDisplay.setSelectionToEnd(); }