set initial state of threshold representation

This commit is contained in:
ameba23
2021-03-04 08:52:52 +01:00
parent 55e5600214
commit 0b9e4915dc

View File

@@ -30,6 +30,8 @@ public class ThresholdSelectorFragment extends BaseFragment {
protected ThresholdDefinedListener listener; protected ThresholdDefinedListener listener;
// TODO this should be the actual number of custodians
private int numberOfCustodians = 5;
private SeekBar seekBar; private SeekBar seekBar;
private TextView thresholdRepresentation; private TextView thresholdRepresentation;
private TextView message; private TextView message;
@@ -54,6 +56,7 @@ public class ThresholdSelectorFragment extends BaseFragment {
seekBar.setOnSeekBarChangeListener(new SeekBarListener()); seekBar.setOnSeekBarChangeListener(new SeekBarListener());
seekBar.setProgress(1); seekBar.setProgress(1);
thresholdRepresentation.setText(buildThresholdRepresentationString(3));
return view; return view;
} }
@@ -91,26 +94,31 @@ public class ThresholdSelectorFragment extends BaseFragment {
} }
} }
private String buildThresholdRepresentationString (int threshold) {
String thresholdRepresentationText = "";
for (int i = 0; i < threshold; i++) {
thresholdRepresentationText += R.string.filled_bullet;
}
for (int i = 0; i < (numberOfCustodians - threshold); i++) {
thresholdRepresentationText += R.string.linear_bullet;
}
return thresholdRepresentationText;
}
private class SeekBarListener implements SeekBar.OnSeekBarChangeListener { private class SeekBarListener implements SeekBar.OnSeekBarChangeListener {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) { boolean fromUser) {
int numCustodians = 5; // TODO this should be the actual number of custodians
// progress can be 0, 1, 2 - translate allowed slider value to actual // progress can be 0, 1, 2 - translate allowed slider value to actual
// threshold // threshold
int threshold = progress + 2; int threshold = progress + 2;
String thresholdRepresentationText = ""; thresholdRepresentation.setText(
for (int i = 0; i < threshold; i++) { buildThresholdRepresentationString(threshold)
thresholdRepresentationText += R.string.filled_bullet; );
}
for (int i = 0; i < (numCustodians - threshold); i++) {
thresholdRepresentationText += R.string.linear_bullet;
}
thresholdRepresentation.setText(thresholdRepresentationText);
int sanityLevel = SecretSharingWrapper.thresholdSanity(threshold, numCustodians); int sanityLevel = SecretSharingWrapper.thresholdSanity(threshold, numberOfCustodians);
int text = R.string.threshold_secure; int text = R.string.threshold_secure;
if (sanityLevel < -1) text = R.string.threshold_low_insecure; if (sanityLevel < -1) text = R.string.threshold_low_insecure;
if (sanityLevel > 1) text = R.string.threshold_high_insecure; if (sanityLevel > 1) text = R.string.threshold_high_insecure;