Skip to content

Calculator settings

maltaisn edited this page Mar 10, 2019 · 7 revisions

Many settings are available to you to change the default behaviour of the calculator. The settings can be changed on the CalcSettings object returned by CalcDialog.getSettings(). Each method returns the settings object to allow method chaining.

Here's an example of changing the settings in Kotlin. All the values used here are the defaults.

val dialog = CalcDialog()
dialog.settings.apply {
    requestCode = 0
    initialValue = null
    numberFormat = NumberFormat.instance
    minValue = BigDecimal("-1e10")
    maxValue = BigDecimal("1e10")
    numpadLayout = CalcNumpadLayout.CALCULATOR
    expressionShown = false
    expressionEditable = false
    zeroShownWhenNoValue = true
    answerBtnShown = false
    signBtnShown = true
    shouldEvaluateOnOperation = true
    orderOfOperationsApplied = true
}

Settings

  • setRequestCode(int requestCode): If you use multiple dialog, this can be used to tell them apart when the callback is called.

  • setInitialValue(@Nullable BigDecimal value): Set initial value to show. It must be within minimum and maximum values. If null, zero will be shown. By default, initial value is null.

  • setNumberFormat(NumberFormat nbFmt): Defines how the numbers entered will appear to the user. DecimalFormat has many different settings, and some of them change how the calculator behaves too:

    • setMaximumIntegerDigits: maximum integer digits than can be typed, but more could be displayed.
    • setMaximumFractionDigits: maximum fraction digits than can be typed and displayed.
    • setDecimalFormatSymbols: change decimal separator, negative sign, grouping symbol, etc.
    • setGroupingUsed: enable or disable grouping, grouping size can also be changed.
    • setRoundingMode: change the rounding mode, also used for division by the calculator.
    • More settings available like prefix, suffix and minimum digits.
  • setMinValue(@Nullable BigDecimal minValue) and setMaxValue(@Nullable BigDecimal maxValue): Set the minimum and maximum values that can be entered with the dialog. Both can be null for no limit. The default values are -10,000,000,000 and 10,000,000,000. If the minimum value is 0 and the user enters a value below it, a "Result must be positive" message will be shown instead of the usual "Out of bounds" message. The same applies to the maximum value.

  • setNumpadLayout(CalcNumpadLayout layout): Set the numpad layout. Two options are available, CalcNumpadLayout.CALCULATOR that shows 789 on the top row (this is the default layout), and CalcNumpadLayout.PHONE that shows 123 on the top row.

  • setExpressionShown(boolean shown): Set whether to show the expression typed on top of the dialog or not. By default it's not shown.

  • setExpressionEditable(boolean editable): Set whether the user can edit the expression after having clicked an operator. If editable and user types 2 + 3 + 4 + 5, it could be erase to 2 + 3 + and changed. This can be enabled even if expression isn't shown but it makes less sense. By default the expression is not editable.

  • setZeroShownWhenNoValue(boolean shown): Set whether zero should be displayed when no value has been entered or just display nothing. This happens when initial value is null, when an error is dismissed, or when an operator is clicked and expression evaluation is disabled. By default the zero is shown.

  • setAnswerBtnShown(boolean shown): Set whether to show the answer button when an operation button is clicked or not. This button allows the user to enter the value that was previously calculated. By default, the answer button is not shown.

  • setSignBtnShown(boolean shown): Set whether the sign button should be shown. By default it is shown.

  • setShouldEvaluateOnOperation(boolean shouldClear): Set whether to evaluate the expression when an operator button is pressed (+, -, * and /). If not, the display will show zero. By default, the expression is evaluated.

  • setOrderOfOperationsApplied(boolean isApplied): Set whether to apply the operation priority on the entered expression, i.e. evaluating products and quotients before, from left to right. If not, the operations are evaluated in the same order as they are entered. By default the order of operations is applied.

Clone this wiki locally