|
29 | 29 | import android.widget.RadioGroup; |
30 | 30 | import android.widget.Spinner; |
31 | 31 | import android.widget.TextView; |
| 32 | +import android.os.Bundle; |
| 33 | +import android.os.Parcelable; |
32 | 34 | import java.util.ArrayList; |
33 | 35 | import java.util.List; |
34 | 36 |
|
@@ -56,10 +58,12 @@ public static int getSignalIndexForSource(int sourceResId) { |
56 | 58 | private OnSettingChangedListener mListener; |
57 | 59 |
|
58 | 60 | public interface OnSettingChangedListener { |
| 61 | + |
59 | 62 | void onSettingChanged(); |
60 | 63 | } |
61 | 64 |
|
62 | 65 | private static class BandInputs { |
| 66 | + |
63 | 67 | EditText startTop; |
64 | 68 | EditText stopTop; |
65 | 69 | EditText startBottom; |
@@ -364,4 +368,66 @@ public FrequencyBandSpec getSpec() { |
364 | 368 | } |
365 | 369 | return new FrequencyBandSpec(anchors, bands, checkType, threshold); |
366 | 370 | } |
| 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 | + } |
367 | 433 | } |
0 commit comments