Skip to content

Commit

Permalink
Add a calculator to get the band for an LTE EARFCN
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrowlands committed Nov 12, 2023
1 parent 1441b5b commit d5e1a8d
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.craxiom.networksurvey.CalculationUtils;
import com.craxiom.networksurvey.R;
import com.craxiom.networksurvey.util.CellularUtils;

import timber.log.Timber;

Expand All @@ -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;

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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.
* <p>
Expand Down
65 changes: 63 additions & 2 deletions networksurvey/src/main/res/layout/fragment_calculator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<com.google.android.material.textfield.TextInputEditText
Expand Down Expand Up @@ -118,7 +118,7 @@
android:id="@+id/lteCalculatorPciTextInputLayout"
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 PCI to calculate the PSS and SSS for."
android:hint="@string/lte_pci_label">

<com.google.android.material.textfield.TextInputEditText
Expand Down Expand Up @@ -182,6 +182,67 @@

</androidx.cardview.widget.CardView>


<androidx.cardview.widget.CardView
android:id="@+id/lte_band_calculator_card_view"
style="?attr/cardStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/calculator_margin"
android:layout_marginEnd="@dimen/calculator_margin"
android:layout_marginBottom="@dimen/calculator_margin"
android:gravity="top"
android:orientation="vertical">

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/lteCalculatorEarfcnTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints="Enter in an LTE EARFCN"
android:hint="@string/lte_earfcn_label">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/lteCalculatorEarfcn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints="Enter in the LTE PCI to calculate the PSS and SSS for"
android:importantForAutofill="no"
android:inputType="number"
android:maxLines="1" />

</com.google.android.material.textfield.TextInputLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/calculator_margin"
android:gravity="top"
android:orientation="horizontal">

<TextView
android:id="@+id/calculatedBand"
style="@style/LabelStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/band_label"
android:textAppearance="@style/LabelText" />

<TextView
android:id="@+id/calculatedBandValue"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="@style/ValueText" />
</LinearLayout>

</LinearLayout>

</androidx.cardview.widget.CardView>

</LinearLayout>

</ScrollView>
2 changes: 2 additions & 0 deletions networksurvey/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,14 @@ but work independently, so you have full control over how you handle your data.<

<string name="pss_label">PSS: </string>
<string name="sss_label">SSS: </string>
<string name="band_label">Band: </string>

<string name="latitude_label">Latitude: %1$s</string>
<string name="longitude_label">Longitude: %1$s</string>

<string name="lte_cell_id_label">&lt;LTE Cell ID&gt;</string>
<string name="lte_pci_label">&lt;LTE PCI&gt;</string>
<string name="lte_earfcn_label">&lt;LTE EARFCN&gt;</string>

<string name="cellular_logging_start_toast">Started Writing the Cellular Log File</string>
<string name="cellular_logging_stop_toast">Cellular Log File Closed</string>
Expand Down

0 comments on commit d5e1a8d

Please sign in to comment.