Skip to content

Commit

Permalink
Add units to the signals and center the signal value on the signal bar
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrowlands committed Apr 11, 2024
1 parent ec0c235 commit 42e2d27
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ private void updateSignalStrengthOne(Integer signalValue)
if (protocol == null) return;

binding.signalOneGroup.setVisibility(signalValue == null ? View.GONE : View.VISIBLE);
binding.signalOneValue.setText(signalValue != null ? getString(R.string.dbm_value_label, String.valueOf(signalValue)) : "");
setSignalStrengthBar(binding.progressBarSignalOne, signalValue, protocol.getMinSignalOne(), protocol.getMaxNormalizedSignalOne());
}

Expand All @@ -943,6 +944,7 @@ private void updateSignalStrengthTwo(Integer signalValue)
}

binding.signalTwoGroup.setVisibility(signalValue == null ? View.GONE : View.VISIBLE);
binding.signalTwoValue.setText(signalValue != null ? getString(R.string.db_value_label, String.valueOf(signalValue)) : "");
setSignalStrengthBar(binding.progressBarSignalTwo, signalValue, protocol.getMinSignalTwo(), protocol.getMaxNormalizedSignalTwo());
}

Expand All @@ -958,6 +960,7 @@ private void updateSignalStrengthThree(Integer signalValue)
if (protocol == null) return;

binding.signalThreeGroup.setVisibility(signalValue == null ? View.GONE : View.VISIBLE);
binding.signalThreeValue.setText(signalValue != null ? getString(R.string.db_value_label, String.valueOf(signalValue)) : "");
setSignalStrengthBar(binding.progressBarSignalThree, signalValue, protocol.getMinSignalThree(), protocol.getMaxNormalizedSignalThree());
}

Expand All @@ -969,12 +972,12 @@ private void updateSignalStrengthThree(Integer signalValue)
*/
private void setSignalStrengthBar(RoundedProgressBar signalStrengthBar, Integer signalValue, int minValue, int maxNormalizedValue)
{
signalStrengthBar.setProgressTextFormatter(new MyProgressTextFormatter(signalValue));
//signalStrengthBar.setProgressTextFormatter(new MyProgressTextFormatter(signalValue));

if (signalValue == null)
{
signalStrengthBar.setProgressPercentage(0, false);
signalStrengthBar.showProgressText(false);
//signalStrengthBar.showProgressText(false);
return;
}

Expand All @@ -986,9 +989,9 @@ private void setSignalStrengthBar(RoundedProgressBar signalStrengthBar, Integer
final int color = ColorUtils.getSignalColorForValue(normalizedValue, maxNormalizedValue);

signalStrengthBar.setProgressDrawableColor(color);
signalStrengthBar.setBackgroundTextColor(color);
//signalStrengthBar.setBackgroundTextColor(color);
signalStrengthBar.setBackgroundColor(ColorUtils.getFadedColor(color));
signalStrengthBar.showProgressText(true);
//signalStrengthBar.showProgressText(true);
// We want there to be at least a small amount of the bar visible, so we set the minimum to 2%.
signalStrengthBar.setProgressPercentage(Math.max(2, scaledNormalizedValue), true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public class ColorUtils
private static final int NUMBER_VALUES = NUMBER_COLORS - 1;

@ColorInt
private static final int[] COLOR_BINS = generateRssiColors(0xFFc20606, 0xFF338a37); // Red and Green
//private static final int[] COLOR_BINS = generateRssiColors(0xFFc20606, 0xFF338a37); // Red and Green
//private static final int[] COLOR_BINS = generateRssiColors(0xFF8a0606, 0xFF215c24); // Red and Green
private static final int[] COLOR_BINS = generateRssiColors(0xFFb50d0d, 0xFF2d8031); // Red and Green

/**
* Generates NUMBER_COLORS colors between the minColor and maxColor (inclusive).
Expand Down Expand Up @@ -59,7 +61,7 @@ private static int[] generateRssiColors(@ColorInt int minColor, @ColorInt int ma
};

// Adjust saturation and lightness to improve the colors
hsl[1] = adjustSaturation(hsl[1], i);
//hsl[1] = adjustSaturation(hsl[1], i);
//hsl[2] = adjustLightness(hsl[2], i);

colors[i] = androidx.core.graphics.ColorUtils.HSLToColor(hsl);
Expand Down Expand Up @@ -152,7 +154,8 @@ public static int getColorForSignalStrength(float signalStrength)
* @param color The original color in ARGB format (e.g., 0xFFRRGGBB).
* @return The faded color with reduced alpha.
*/
public static int getFadedColor(int color) {
public static int getFadedColor(int color)
{
// Set the alpha to 10% of its full value to make the color really faded
int fadedAlpha = (int) (255 * 0.1); // You can adjust the 0.1 to make it more or less faded

Expand Down
53 changes: 46 additions & 7 deletions networksurvey/src/main/res/layout/fragment_network_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,10 @@
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="@dimen/medium_margin"
android:layout_marginStart="@dimen/small_margin"
android:layout_marginEnd="@dimen/medium_margin"
android:layout_marginTop="@dimen/medium_margin"
android:layout_marginBottom="@dimen/medium_margin"
android:orientation="vertical">

<androidx.constraintlayout.widget.ConstraintLayout
Expand All @@ -587,8 +590,20 @@
app:rpbProgressColor="@color/colorAccent"
app:rpbProgressTextColor="@color/normalText"
app:rpbTextPadding="5dp"
app:rpbAnimationLength="@integer/material_motion_duration_long_2"
app:rpbTextSize="@dimen/signal_bar_text_size" />
app:rpbAnimationLength="600" />

<TextView
android:id="@+id/signal_one_value"
style="@style/StandardText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/normalText"
app:layout_constraintStart_toStartOf="@id/progress_bar_signal_one"
app:layout_constraintEnd_toEndOf="@id/progress_bar_signal_one"
app:layout_constraintTop_toTopOf="@id/progress_bar_signal_one"
app:layout_constraintBottom_toBottomOf="@id/progress_bar_signal_one"
android:gravity="center" />

</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down Expand Up @@ -624,8 +639,20 @@
app:rpbProgressColor="@color/colorAccent"
app:rpbProgressTextColor="@color/normalText"
app:rpbTextPadding="5dp"
app:rpbAnimationLength="@integer/material_motion_duration_long_2"
app:rpbTextSize="@dimen/signal_bar_text_size" />
app:rpbAnimationLength="600" />

<TextView
android:id="@+id/signal_two_value"
style="@style/StandardText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/normalText"
app:layout_constraintStart_toStartOf="@id/progress_bar_signal_two"
app:layout_constraintEnd_toEndOf="@id/progress_bar_signal_two"
app:layout_constraintTop_toTopOf="@id/progress_bar_signal_two"
app:layout_constraintBottom_toBottomOf="@id/progress_bar_signal_two"
android:gravity="center" />

</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down Expand Up @@ -661,8 +688,20 @@
app:rpbProgressColor="@color/colorAccent"
app:rpbProgressTextColor="@color/normalText"
app:rpbTextPadding="5dp"
app:rpbAnimationLength="@integer/material_motion_duration_long_2"
app:rpbTextSize="@dimen/signal_bar_text_size" />
app:rpbAnimationLength="600" />

<TextView
android:id="@+id/signal_three_value"
style="@style/StandardText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/normalText"
app:layout_constraintStart_toStartOf="@id/progress_bar_signal_three"
app:layout_constraintEnd_toEndOf="@id/progress_bar_signal_three"
app:layout_constraintTop_toTopOf="@id/progress_bar_signal_three"
app:layout_constraintBottom_toBottomOf="@id/progress_bar_signal_three"
android:gravity="center" />

</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down
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 @@ -113,6 +113,8 @@ but work independently, so you have full control over how you handle your data.<
<string name="rsrp_label">RSRP</string>
<string name="rsrq_label">RSRQ</string>
<string name="snr_label">SNR</string>
<string name="dbm_value_label">%1$s dBm</string>
<string name="db_value_label">%1$s dB</string>

<!-- NR labels -->
<string name="narfcn_label">NARFCN</string>
Expand Down

0 comments on commit 42e2d27

Please sign in to comment.