Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Inside Gradle Scripts -> dependencies
- implementation 'com.faendir.rhino:rhino-android:1.5.2'
- // Equal method
- btnEqual.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- String text = input.getText().toString();
- if ("".equals(text)) {
- startPar = false;
- return;
- }
- output.setText(text);
- text = text.replaceAll("รท", "/");
- text = text.replaceAll("%", "/100");
- text = text.replaceAll("ร", "*");
- text = text.replaceAll("โ", "-");
- text = text.replaceAll("Mod", "%");
- org.mozilla.javascript.Context rhino = Context.enter();
- rhino.setOptimizationLevel(-1);
- String result = "";
- try {
- Scriptable scriptable = rhino.initStandardObjects();
- result = rhino.evaluateString(scriptable, text, "javascript", 1, null).toString();
- }
- catch (Exception e) {
- result = "0";
- }
- if (result.length() > 10) {
- input.setTextSize(TypedValue.COMPLEX_UNIT_SP, 37);
- }
- input.setText(result);
- startPar = false;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement