persist the 3 values across activity creation

This commit is contained in:
Dan Ballard 2017-09-23 08:34:50 -07:00
parent fd5b1826de
commit 14fc595760
1 changed files with 25 additions and 6 deletions

View File

@ -10,6 +10,10 @@ import android.widget.TextView;
import goRicochetMobile.GoRicochetMobile;
public class RemoteActivity extends AppCompatActivity {
private static final String DEVICE_NAME_KEY = "deviceName";
private static final String BATTERY_LEVEL_KEY = "batteryLevel";
private static final String VIBE_LEVEL_KEY = "vibeLEvel";
TextView deviceText;
TextView batteryText;
TextView statusText;
@ -62,14 +66,29 @@ public class RemoteActivity extends AppCompatActivity {
}
});
GetDeviceNameTask getDeviceNameTask = new GetDeviceNameTask();
getDeviceNameTask.execute();
GetBatteryTask getBatteryTask = new GetBatteryTask();
getBatteryTask.execute();
if (savedInstanceState != null) {
deviceText.setText(savedInstanceState.getString(DEVICE_NAME_KEY));
batteryText.setText(savedInstanceState.getString(BATTERY_LEVEL_KEY));
vibeLevel = savedInstanceState.getInt(VIBE_LEVEL_KEY);
setVibeLevel(vibeLevel);
} else {
GetDeviceNameTask getDeviceNameTask = new GetDeviceNameTask();
getDeviceNameTask.execute();
GetLevelTask getLevelTask = new GetLevelTask();
getLevelTask.execute();
GetBatteryTask getBatteryTask = new GetBatteryTask();
getBatteryTask.execute();
GetLevelTask getLevelTask = new GetLevelTask();
getLevelTask.execute();
}
}
@Override
protected void onSaveInstanceState(final Bundle outState) {
outState.putString(DEVICE_NAME_KEY, deviceText.getText().toString());
outState.putString(BATTERY_LEVEL_KEY, batteryText.getText().toString());
outState.putInt(VIBE_LEVEL_KEY, vibeLevel);
}
// current impelementation of OD server can return 0 to 6 (potentially downsampled from 12?)