Skip to content

Commit f578e2b

Browse files
committed
[Frequency tests] Save instance state
1 parent 27f0083 commit f578e2b

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

apps/OboeTester/app/src/main/java/com/mobileer/oboetester/FrequencySettingView.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import android.widget.RadioGroup;
3030
import android.widget.Spinner;
3131
import android.widget.TextView;
32+
import android.os.Bundle;
33+
import android.os.Parcelable;
3234
import java.util.ArrayList;
3335
import java.util.List;
3436

@@ -56,10 +58,12 @@ public static int getSignalIndexForSource(int sourceResId) {
5658
private OnSettingChangedListener mListener;
5759

5860
public interface OnSettingChangedListener {
61+
5962
void onSettingChanged();
6063
}
6164

6265
private static class BandInputs {
66+
6367
EditText startTop;
6468
EditText stopTop;
6569
EditText startBottom;
@@ -364,4 +368,66 @@ public FrequencyBandSpec getSpec() {
364368
}
365369
return new FrequencyBandSpec(anchors, bands, checkType, threshold);
366370
}
371+
372+
@Override
373+
protected Parcelable onSaveInstanceState() {
374+
Bundle bundle = new Bundle();
375+
bundle.putParcelable("superState", super.onSaveInstanceState());
376+
377+
String[] anchorTexts = new String[mFrequencyAnchorInputs.size()];
378+
for (int i = 0; i < mFrequencyAnchorInputs.size(); i++) {
379+
anchorTexts[i] = mFrequencyAnchorInputs.get(i).getText().toString();
380+
}
381+
bundle.putStringArray("anchors", anchorTexts);
382+
383+
String[] startTopTexts = new String[mBandInputsList.size()];
384+
String[] stopTopTexts = new String[mBandInputsList.size()];
385+
String[] startBotTexts = new String[mBandInputsList.size()];
386+
String[] stopBotTexts = new String[mBandInputsList.size()];
387+
for (int i = 0; i < mBandInputsList.size(); i++) {
388+
BandInputs bi = mBandInputsList.get(i);
389+
startTopTexts[i] = bi.startTop.getText().toString();
390+
stopTopTexts[i] = bi.stopTop.getText().toString();
391+
startBotTexts[i] = bi.startBottom.getText().toString();
392+
stopBotTexts[i] = bi.stopBottom.getText().toString();
393+
}
394+
bundle.putStringArray("startTop", startTopTexts);
395+
bundle.putStringArray("stopTop", stopTopTexts);
396+
bundle.putStringArray("startBot", startBotTexts);
397+
bundle.putStringArray("stopBot", stopBotTexts);
398+
399+
return bundle;
400+
}
401+
402+
@Override
403+
protected void onRestoreInstanceState(Parcelable state) {
404+
if (state instanceof Bundle) {
405+
Bundle bundle = (Bundle) state;
406+
super.onRestoreInstanceState(bundle.getParcelable("superState"));
407+
408+
String[] anchorTexts = bundle.getStringArray("anchors");
409+
if (anchorTexts != null) {
410+
for (int i = 0; i < anchorTexts.length && i < mFrequencyAnchorInputs.size(); i++) {
411+
mFrequencyAnchorInputs.get(i).setText(anchorTexts[i]);
412+
}
413+
}
414+
415+
String[] startTopTexts = bundle.getStringArray("startTop");
416+
String[] stopTopTexts = bundle.getStringArray("stopTop");
417+
String[] startBotTexts = bundle.getStringArray("startBot");
418+
String[] stopBotTexts = bundle.getStringArray("stopBot");
419+
if (startTopTexts != null && stopTopTexts != null && startBotTexts != null
420+
&& stopBotTexts != null) {
421+
for (int i = 0; i < mBandInputsList.size() && i < startTopTexts.length; i++) {
422+
BandInputs bi = mBandInputsList.get(i);
423+
bi.startTop.setText(startTopTexts[i]);
424+
bi.stopTop.setText(stopTopTexts[i]);
425+
bi.startBottom.setText(startBotTexts[i]);
426+
bi.stopBottom.setText(stopBotTexts[i]);
427+
}
428+
}
429+
} else {
430+
super.onRestoreInstanceState(state);
431+
}
432+
}
367433
}

0 commit comments

Comments
 (0)