From 84e15249b3bc6afca925d73db6f539e004271013 Mon Sep 17 00:00:00 2001 From: Tuomas Airaksinen Date: Thu, 6 Oct 2022 13:32:51 +0300 Subject: [PATCH 1/8] EventBus -> ABEventBus --- app/src/main/res/drawable/ic_baseline_calculate_24.xml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 app/src/main/res/drawable/ic_baseline_calculate_24.xml diff --git a/app/src/main/res/drawable/ic_baseline_calculate_24.xml b/app/src/main/res/drawable/ic_baseline_calculate_24.xml new file mode 100644 index 0000000000..36f0426d30 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_calculate_24.xml @@ -0,0 +1,5 @@ + + + From bdbc609092616bd22e98e2b78dcb97c9b0d33532 Mon Sep 17 00:00:00 2001 From: Tuomas Airaksinen Date: Thu, 6 Oct 2022 13:35:43 +0300 Subject: [PATCH 2/8] Enable changing app label and icon via settings --- app/src/main/AndroidManifest.xml | 29 +++++++++++++++++-- .../view/activity/page/MainBibleActivity.kt | 1 + .../activity/settings/SettingsActivity.kt | 3 +- .../net/bible/service/common/CommonUtils.kt | 24 +++++++++++++++ .../res/drawable/ic_baseline_calculate_24.xml | 19 +++++++++++- app/src/main/res/values/strings.xml | 4 +++ app/src/main/res/xml/settings.xml | 6 ++++ 7 files changed, 81 insertions(+), 5 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 39e6e46383..f35340be6d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,11 +48,18 @@ - + + @@ -60,7 +67,23 @@ - + + + + + + + + + + = listOf( + "net.bible.android.view.activity.Bible", + "net.bible.android.view.activity.Calculator" + ) + val activeName = allNames[if(discrete) 1 else 0] + + Log.d(TAG, "Changing app icon / name to $activeName") + + for (name in allNames) { + application.packageManager.setComponentEnabledSetting( + ComponentName(packageName, name), + if(name == activeName) + PackageManager.COMPONENT_ENABLED_STATE_ENABLED + else PackageManager.COMPONENT_ENABLED_STATE_DISABLED, + 0 + ) + } + } } @Serializable diff --git a/app/src/main/res/drawable/ic_baseline_calculate_24.xml b/app/src/main/res/drawable/ic_baseline_calculate_24.xml index 36f0426d30..ea1be3b1c9 100644 --- a/app/src/main/res/drawable/ic_baseline_calculate_24.xml +++ b/app/src/main/res/drawable/ic_baseline_calculate_24.xml @@ -1,4 +1,21 @@ - + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 21d24f7089..e6c03bbb57 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -21,6 +21,8 @@ @author Martin Denham [mjdenham at gmail dot com] --> + Calculator + Bible Study Bible Study (And Bible) AndBible: Bible Study @@ -1027,5 +1029,7 @@ Tap each quick filter button to activate or deactivate them. Long-press quick filter button to remove it. To show progress status notification (download status, index processing etc), we need your permission. + Discrete mode + Hide religious symbols. Show calculator icon and name in launcher instead. diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index fa6e64f1e0..76d274795f 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -142,6 +142,12 @@ android:title="@string/prefs_request_sdcard_permission_title" android:summary="@string/prefs_request_sdcard_permission_summary" android:defaultValue="false"/> + Date: Thu, 6 Oct 2022 13:56:19 +0300 Subject: [PATCH 3/8] Add settings for calculator app --- .../activity/settings/SettingsActivity.kt | 10 ++++++- app/src/main/res/values/strings.xml | 5 ++++ app/src/main/res/xml/settings.xml | 27 ++++++++++++++----- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/net/bible/android/view/activity/settings/SettingsActivity.kt b/app/src/main/java/net/bible/android/view/activity/settings/SettingsActivity.kt index 6d5ae78767..643cb2cde3 100644 --- a/app/src/main/java/net/bible/android/view/activity/settings/SettingsActivity.kt +++ b/app/src/main/java/net/bible/android/view/activity/settings/SettingsActivity.kt @@ -19,8 +19,10 @@ package net.bible.android.view.activity.settings import android.app.AlertDialog import android.os.Build import android.os.Bundle +import android.text.InputType import android.view.Menu import android.view.MenuItem +import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceCategory @@ -127,7 +129,9 @@ class SettingsActivity: ActivityBase() { "night_mode_pref3", "request_sdcard_permission_pref", "show_errorbox", - "discrete_mode" + "discrete_mode", + "show_calculator", + "calculator_pin", ) for(key in keys) { editor.removeString(key) @@ -210,6 +214,10 @@ class SettingsFragment : PreferenceFragmentCompat() { pref.isVisible = false } + (preferenceScreen.findPreference("calculator_pin") as EditTextPreference).apply { + setOnBindEditTextListener { it.inputType = InputType.TYPE_CLASS_NUMBER } + } + for(p in getPreferenceList()) { val icon = p.icon if(icon != null) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e6c03bbb57..1a29986547 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1031,5 +1031,10 @@ To show progress status notification (download status, index processing etc), we need your permission. Discrete mode Hide religious symbols. Show calculator icon and name in launcher instead. + Settings for the persecuted + Show calculator smoke screen + When launching app, show calculator app. You can set up your pin code to get into actual bible app. + Calculator pin + "Pin code to enter app, if smoke calculator is enabled. " diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 76d274795f..8743b9538b 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -132,6 +132,27 @@ /> + + + + + + - Date: Thu, 6 Oct 2022 15:43:33 +0300 Subject: [PATCH 4/8] Add calculator activity From https://github.com/eloyzone/android-calculator (GPL3) --- app/build.gradle.kts | 1 + app/src/main/AndroidManifest.xml | 4 + .../android/view/activity/StartupActivity.kt | 10 +- .../activity/discrete/CalculatorActivity.java | 528 ++++++++++++++++++ app/src/main/res/layout/calculator_layout.xml | 282 ++++++++++ 5 files changed, 824 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/net/bible/android/view/activity/discrete/CalculatorActivity.java create mode 100644 app/src/main/res/layout/calculator_layout.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 38966f3c86..b4b7408f58 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -291,6 +291,7 @@ dependencies { implementation("androidx.preference:preference-ktx:1.2.0") implementation("androidx.recyclerview:recyclerview:1.2.1") implementation("androidx.webkit:webkit:1.5.0") + implementation("io.apisense:rhino-android:1.0") //implementation("androidx.recyclerview:recyclerview-selection:1.0.0") diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f35340be6d..4e9a4ebdde 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -265,6 +265,10 @@ + 0 && operationLength > 0) + { + String lastInput = textViewInputNumbers.getText().charAt(operationLength - 1) + ""; + switch (defineLastCharacter(lastInput)) + { + case IS_NUMBER: + textViewInputNumbers.setText(textViewInputNumbers.getText() + ")"); + done = true; + openParenthesis--; + dotUsed = false; + break; + case IS_OPERAND: + textViewInputNumbers.setText(textViewInputNumbers.getText() + "("); + done = true; + openParenthesis++; + dotUsed = false; + break; + case IS_OPEN_PARENTHESIS: + textViewInputNumbers.setText(textViewInputNumbers.getText() + "("); + done = true; + openParenthesis++; + dotUsed = false; + break; + case IS_CLOSE_PARENTHESIS: + textViewInputNumbers.setText(textViewInputNumbers.getText() + ")"); + done = true; + openParenthesis--; + dotUsed = false; + break; + } + } else if (openParenthesis == 0 && operationLength > 0) + { + String lastInput = textViewInputNumbers.getText().charAt(operationLength - 1) + ""; + if (defineLastCharacter(lastInput) == IS_OPERAND) + { + textViewInputNumbers.setText(textViewInputNumbers.getText() + "("); + done = true; + dotUsed = false; + openParenthesis++; + } else + { + textViewInputNumbers.setText(textViewInputNumbers.getText() + "x("); + done = true; + dotUsed = false; + openParenthesis++; + } + } + return done; + } + + private boolean addOperand(String operand) + { + boolean done = false; + int operationLength = textViewInputNumbers.getText().length(); + if (operationLength > 0) + { + String lastInput = textViewInputNumbers.getText().charAt(operationLength - 1) + ""; + + if ((lastInput.equals("+") || lastInput.equals("-") || lastInput.equals("*") || lastInput.equals("\u00F7") || lastInput.equals("%"))) + { + Toast.makeText(getApplicationContext(), "Wrong format", Toast.LENGTH_LONG).show(); + } else if (operand.equals("%") && defineLastCharacter(lastInput) == IS_NUMBER) + { + textViewInputNumbers.setText(textViewInputNumbers.getText() + operand); + dotUsed = false; + equalClicked = false; + lastExpression = ""; + done = true; + } else if (!operand.equals("%")) + { + textViewInputNumbers.setText(textViewInputNumbers.getText() + operand); + dotUsed = false; + equalClicked = false; + lastExpression = ""; + done = true; + } + } else + { + Toast.makeText(getApplicationContext(), "Wrong Format. Operand Without any numbers?", Toast.LENGTH_LONG).show(); + } + return done; + } + + private boolean addNumber(String number) + { + boolean done = false; + int operationLength = textViewInputNumbers.getText().length(); + if (operationLength > 0) + { + String lastCharacter = textViewInputNumbers.getText().charAt(operationLength - 1) + ""; + int lastCharacterState = defineLastCharacter(lastCharacter); + + if (operationLength == 1 && lastCharacterState == IS_NUMBER && lastCharacter.equals("0")) + { + textViewInputNumbers.setText(number); + done = true; + } else if (lastCharacterState == IS_OPEN_PARENTHESIS) + { + textViewInputNumbers.setText(textViewInputNumbers.getText() + number); + done = true; + } else if (lastCharacterState == IS_CLOSE_PARENTHESIS || lastCharacter.equals("%")) + { + textViewInputNumbers.setText(textViewInputNumbers.getText() + "x" + number); + done = true; + } else if (lastCharacterState == IS_NUMBER || lastCharacterState == IS_OPERAND || lastCharacterState == IS_DOT) + { + textViewInputNumbers.setText(textViewInputNumbers.getText() + number); + done = true; + } + } else + { + textViewInputNumbers.setText(textViewInputNumbers.getText() + number); + done = true; + } + return done; + } + + + private void calculate(String input) + { + String result = ""; + try + { + String temp = input; + if (equalClicked) + { + temp = input + lastExpression; + } else + { + saveLastExpression(input); + } + result = scriptEngine.eval(temp.replaceAll("%", "/100").replaceAll("x", "*").replaceAll("[^\\x00-\\x7F]", "/")).toString(); + BigDecimal decimal = new BigDecimal(result); + result = decimal.setScale(8, BigDecimal.ROUND_HALF_UP).toPlainString(); + equalClicked = true; + + } catch (Exception e) + { + Toast.makeText(getApplicationContext(), "Wrong Format", Toast.LENGTH_SHORT).show(); + return; + } + + if (result.equals("Infinity")) + { + Toast.makeText(getApplicationContext(), "Division by zero is not allowed", Toast.LENGTH_SHORT).show(); + textViewInputNumbers.setText(input); + + } else if (result.contains(".")) + { + result = result.replaceAll("\\.?0*$", ""); + textViewInputNumbers.setText(result); + } + } + + private void saveLastExpression(String input) + { + String lastOfExpression = input.charAt(input.length() - 1) + ""; + if (input.length() > 1) + { + if (lastOfExpression.equals(")")) + { + lastExpression = ")"; + int numberOfCloseParenthesis = 1; + + for (int i = input.length() - 2; i >= 0; i--) + { + if (numberOfCloseParenthesis > 0) + { + String last = input.charAt(i) + ""; + if (last.equals(")")) + { + numberOfCloseParenthesis++; + } else if (last.equals("(")) + { + numberOfCloseParenthesis--; + } + lastExpression = last + lastExpression; + } else if (defineLastCharacter(input.charAt(i) + "") == IS_OPERAND) + { + lastExpression = input.charAt(i) + lastExpression; + break; + } else + { + lastExpression = ""; + } + } + } else if (defineLastCharacter(lastOfExpression + "") == IS_NUMBER) + { + lastExpression = lastOfExpression; + for (int i = input.length() - 2; i >= 0; i--) + { + String last = input.charAt(i) + ""; + if (defineLastCharacter(last) == IS_NUMBER || defineLastCharacter(last) == IS_DOT) + { + lastExpression = last + lastExpression; + } else if (defineLastCharacter(last) == IS_OPERAND) + { + lastExpression = last + lastExpression; + break; + } + if (i == 0) + { + lastExpression = ""; + } + } + } + } + } + + private int defineLastCharacter(String lastCharacter) + { + try + { + Integer.parseInt(lastCharacter); + return IS_NUMBER; + } catch (NumberFormatException e) + { + } + + if ((lastCharacter.equals("+") || lastCharacter.equals("-") || lastCharacter.equals("x") || lastCharacter.equals("\u00F7") || lastCharacter.equals("%"))) + return IS_OPERAND; + + if (lastCharacter.equals("(")) + return IS_OPEN_PARENTHESIS; + + if (lastCharacter.equals(")")) + return IS_CLOSE_PARENTHESIS; + + if (lastCharacter.equals(".")) + return IS_DOT; + + return -1; + } + + + +} diff --git a/app/src/main/res/layout/calculator_layout.xml b/app/src/main/res/layout/calculator_layout.xml new file mode 100644 index 0000000000..2917c47ed4 --- /dev/null +++ b/app/src/main/res/layout/calculator_layout.xml @@ -0,0 +1,282 @@ + + + + + + + + + + + + + + + +