Fixed MainActivity rotation issue
This commit is contained in:
parent
bb9e55e12d
commit
531de6250d
1 changed files with 38 additions and 31 deletions
|
|
@ -40,6 +40,7 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
||||||
|
|
||||||
/** Fragments **/
|
/** Fragments **/
|
||||||
private StatusFragment statusFragment;
|
private StatusFragment statusFragment;
|
||||||
|
private MenuItem action_execute;
|
||||||
private boolean backButtonPressed = false;
|
private boolean backButtonPressed = false;
|
||||||
|
|
||||||
private static UeControlExecutor currentExecutor;
|
private static UeControlExecutor currentExecutor;
|
||||||
|
|
@ -64,26 +65,28 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
||||||
getFragmentManager().findFragmentById(R.id.status_fragment);
|
getFragmentManager().findFragmentById(R.id.status_fragment);
|
||||||
getFragmentManager().beginTransaction()
|
getFragmentManager().beginTransaction()
|
||||||
.replace(R.id.container, BehaviourListFragment.newInstance()).commit();
|
.replace(R.id.container, BehaviourListFragment.newInstance()).commit();
|
||||||
|
action_execute = (MenuItem) findViewById(R.id.action_execute);
|
||||||
|
|
||||||
|
if(currentExecutor == null) {
|
||||||
currentExecutor = new UeControlExecutor();
|
currentExecutor = new UeControlExecutor();
|
||||||
currentExecutor.setThroughputListener(statusFragment.getThroughputListener());
|
currentExecutor.setThroughputListener(statusFragment.getThroughputListener());
|
||||||
File input = new File(this.getFilesDir(), BEHAVIOUR_SAVE_FILE);
|
File input = new File(this.getFilesDir(), BEHAVIOUR_SAVE_FILE);
|
||||||
if(input.exists()) {
|
if (input.exists()) {
|
||||||
try {
|
try {
|
||||||
log.debug("Reading saved state");
|
log.debug("Reading saved state");
|
||||||
currentExecutor.read(input.getAbsolutePath());
|
currentExecutor.read(input.getAbsolutePath());
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
Toast.makeText(this, "Unable to load saved state", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Unable to load saved state", Toast.LENGTH_SHORT).show();
|
||||||
log.error(null, e);
|
log.error(null, e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.debug("No saved state found, creating default behaviours");
|
||||||
|
currentExecutor.addBehaviour(new UeBehaviourSleep());
|
||||||
|
currentExecutor.addBehaviour(new UeBehaviourSurfing());
|
||||||
|
currentExecutor.addBehaviour(new UeBehaviourSleep(4000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
updateExecutionState();
|
||||||
log.debug("No saved state found, creating default behaviours");
|
|
||||||
currentExecutor.addBehaviour(new UeBehaviourSleep());
|
|
||||||
currentExecutor.addBehaviour(new UeBehaviourSurfing());
|
|
||||||
currentExecutor.addBehaviour(new UeBehaviourSleep(4000));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -141,20 +144,7 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
||||||
// as you specify a parent activity in AndroidManifest.xml.
|
// as you specify a parent activity in AndroidManifest.xml.
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
if (id == R.id.action_execute) {
|
if (id == R.id.action_execute) {
|
||||||
if(currentExecutor.isRunning()){
|
updateExecutionState();
|
||||||
currentExecutor.terminate();
|
|
||||||
item.setTitle(R.string.action_run);
|
|
||||||
csvLogger = null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
if(prefs.getBoolean("logging", true))
|
|
||||||
csvLogger = new CSVWriter(this);
|
|
||||||
else
|
|
||||||
csvLogger = null;
|
|
||||||
currentExecutor.execute();
|
|
||||||
item.setTitle(R.string.action_stop);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (id == R.id.action_edit) {
|
else if (id == R.id.action_edit) {
|
||||||
|
|
@ -173,6 +163,23 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateExecutionState(){
|
||||||
|
if(currentExecutor.isRunning()){
|
||||||
|
currentExecutor.terminate();
|
||||||
|
action_execute.setTitle(R.string.action_run);
|
||||||
|
csvLogger = null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
if(prefs.getBoolean("logging", true))
|
||||||
|
csvLogger = new CSVWriter(this);
|
||||||
|
else
|
||||||
|
csvLogger = null;
|
||||||
|
currentExecutor.execute();
|
||||||
|
action_execute.setTitle(R.string.action_stop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue