More Calculator Functions

From WebOS Internals
Revision as of 16:39, 31 July 2009 by Shane112358 (talk | contribs)
Jump to navigation Jump to search

Bottom line - there are secondary calculator functions already built in. Just push the space bar. Below is the coding showing where I found it. I'm currently working on replacing some of the functions with more useful ones (like x^y)...Go to bottom for that.

If you go to

/usr/palm/applications/com.palm.app.calculator/app/controllers

and look at calculator-assistant.js, you can see the following alternative functions that have always been available - but news to me.

onKeyPress: function(event) {
                if (Mojo.Char.isEnterKey(event.charCode)) {
                        this.onEqualsPress(event);
                } else if (event.charCode == Mojo.Char.backspace) {
                        this.onBackspacePress(event);
                } else if (event.charCode == Mojo.Char.spaceBar) {
                        this.toggleOptionKeyMode();
.
.
.
.
 onDividePress: function(event) {
                if (this.optionKeys) {
                        this.calculator.memMinus();
                        this.showMemoryIndicator();
                        this.toggleOptionKeyMode();
                } else {
                        this.calculator.divide();
                }
                this.updateResults();
                event.stop();
        },

        onMultiplyPress: function(event) {
                if (this.optionKeys) {
                        this.calculator.percent();
                        this.toggleOptionKeyMode();
                } else {
                        this.calculator.multiply();
                }
                this.updateResults();
                event.stop();
        },
 onSubtractPress: function(event) {
                if (this.optionKeys) {
                        this.calculator.sqrt();
                        this.toggleOptionKeyMode();
                } else {
                        this.calculator.subtract();
                }
                this.updateResults();
                event.stop();
        },

        onAddPress: function(event) {
                if (this.optionKeys) {
                        this.calculator.plusMinus();
                        this.toggleOptionKeyMode();
                } else {
                        this.calculator.add();
                }
                this.updateResults();
                event.stop();
        },

To change the functions, you can head to

/usr/palm/applications/com.palm.app.calculator/app/models/calculator.js

At line 183 is

percent: function() {
                this.xReg = this.xReg / 100;
                this.inputBuffer = '' + this.xReg;

Currently working on changing these to math.pow functions, etc. Bear with me, I'm new Java...