From d5e1a8d157e93e2cd7287fa1181c15fce6694ba9 Mon Sep 17 00:00:00 2001 From: christianrowlands Date: Sun, 12 Nov 2023 14:25:53 -0500 Subject: [PATCH] Add a calculator to get the band for an LTE EARFCN --- .../fragments/CalculatorFragment.java | 81 ++++++++++++++++++- .../main/res/layout/fragment_calculator.xml | 65 ++++++++++++++- networksurvey/src/main/res/values/strings.xml | 2 + 3 files changed, 142 insertions(+), 6 deletions(-) diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/CalculatorFragment.java b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/CalculatorFragment.java index 299c646c7..7c7cd85c5 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/CalculatorFragment.java +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/fragments/CalculatorFragment.java @@ -14,6 +14,7 @@ import com.craxiom.networksurvey.CalculationUtils; import com.craxiom.networksurvey.R; +import com.craxiom.networksurvey.util.CellularUtils; import timber.log.Timber; @@ -25,8 +26,9 @@ public class CalculatorFragment extends Fragment { static final String TITLE = "Calculators"; - private static final String INVALID_CELL_ID_MESSAGE = "Invalid Cell ID. Valid Range is 0 - 268435455"; - private static final String INVALID_PCI_MESSAGE = "Invalid PCI. Valid Range is 0 - 503"; + private static final String INVALID_CELL_ID_MESSAGE = "Invalid Cell ID. Valid Range is 0 - 268435455"; + private static final String INVALID_PCI_MESSAGE = "Invalid PCI. Valid Range is 0 - 503"; + private static final String INVALID_EARFCN_MESSAGE = "Invalid EARFCN. Valid Range is 0 - 262143"; private View view; @@ -40,7 +42,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { if (enteredText.isEmpty()) { - Timber.v("The entered text for the LTE Cell ID is empty. Can't calculate the eNodeB ID."); + Timber.v("The entered text for the LTE Cell ID is empty. Can't calculate the eNodeB ID."); clearCellIdCalculatedValues(); return; } @@ -99,7 +101,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { if (enteredText.isEmpty()) { - Timber.v("The entered text for the LTE PCI is empty. Can't calculate the PSS and SSS."); + Timber.v("The entered text for the LTE PCI is empty. Can't calculate the PSS and SSS."); clearPciCalculatedValues(); return; } @@ -146,6 +148,66 @@ public void afterTextChanged(Editable s) } }; + private final TextWatcher lteEarfcnTextWatcher = new TextWatcher() + { + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) + { + final String enteredText = s.toString(); + try + { + if (enteredText.isEmpty()) + { + Timber.v("The entered text for the LTE EARFCN is empty. Can't calculate the Band."); + clearEarfcnCalculatedValues(); + return; + } + + final int earfcn; + try + { + earfcn = Integer.parseInt(enteredText); + } catch (Exception e) + { + showToast(INVALID_EARFCN_MESSAGE); + clearEarfcnCalculatedValues(); + return; + } + + if (earfcn < 0 || earfcn > 262143) + { + showToast(INVALID_EARFCN_MESSAGE); + clearEarfcnCalculatedValues(); + return; + } + + int band = CellularUtils.downlinkEarfcnToBand(earfcn); + if (band == -1) + { + ((TextView) view.findViewById(R.id.calculatedBandValue)).setText("Unknown"); + } else + { + ((TextView) view.findViewById(R.id.calculatedBandValue)).setText(String.valueOf(band)); + } + } catch (Exception e) + { + Timber.w(e, "Unable to parse the provide LTE EARFCN as an Integer:%s", enteredText); + } + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) + { + + } + + @Override + public void afterTextChanged(Editable s) + { + + } + }; + public CalculatorFragment() { // Required empty public constructor @@ -164,6 +226,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, final EditText pciField = view.findViewById(R.id.lteCalculatorPci); pciField.addTextChangedListener(ltePciTextWatcher); + final EditText earfcnField = view.findViewById(R.id.lteCalculatorEarfcn); + earfcnField.addTextChangedListener(lteEarfcnTextWatcher); + return view; } @@ -185,6 +250,14 @@ private void clearPciCalculatedValues() ((TextView) view.findViewById(R.id.calculatedSssValue)).setText(""); } + /** + * Sets the text in the Band calculated TextView to an empty string. + */ + private void clearEarfcnCalculatedValues() + { + ((TextView) view.findViewById(R.id.calculatedBandValue)).setText(""); + } + /** * Shows a short toast to the user with the provided message. *

diff --git a/networksurvey/src/main/res/layout/fragment_calculator.xml b/networksurvey/src/main/res/layout/fragment_calculator.xml index 4910f736d..5621266ea 100644 --- a/networksurvey/src/main/res/layout/fragment_calculator.xml +++ b/networksurvey/src/main/res/layout/fragment_calculator.xml @@ -32,7 +32,7 @@ android:id="@+id/lteCalculatorCellIdTextInputLayout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:autofillHints="Enter in the Host address of the remote gRPC server" + android:autofillHints="Enter in an LTE Cell ID" android:hint="@string/lte_cell_id_label"> + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/networksurvey/src/main/res/values/strings.xml b/networksurvey/src/main/res/values/strings.xml index 105b1481a..9e355ce2d 100644 --- a/networksurvey/src/main/res/values/strings.xml +++ b/networksurvey/src/main/res/values/strings.xml @@ -168,12 +168,14 @@ but work independently, so you have full control over how you handle your data.< PSS: SSS: + Band: Latitude: %1$s Longitude: %1$s <LTE Cell ID> <LTE PCI> + <LTE EARFCN> Started Writing the Cellular Log File Cellular Log File Closed