Fixed issue where Run button was showing wrong state
This commit is contained in:
parent
38c4a56a97
commit
f5e95e683c
5 changed files with 69 additions and 30 deletions
|
|
@ -64,10 +64,11 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
statusFragment = (StatusFragment)
|
||||
getFragmentManager().findFragmentById(R.id.status_fragment);
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(R.id.container, BehaviourListFragment.newInstance()).commit();
|
||||
action_execute = (MenuItem) findViewById(R.id.action_execute);
|
||||
.replace(R.id.container, new BehaviourListFragment()).commit();
|
||||
|
||||
|
||||
if(currentExecutor == null) {
|
||||
log.info("Creating new instance of executor");
|
||||
currentExecutor = new UeControlExecutor();
|
||||
currentExecutor.setThroughputListener(statusFragment.getThroughputListener());
|
||||
File input = new File(this.getFilesDir(), BEHAVIOUR_SAVE_FILE);
|
||||
|
|
@ -86,6 +87,8 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
currentExecutor.addBehaviour(new UeBehaviourSleep(4000));
|
||||
}
|
||||
}
|
||||
else
|
||||
log.info("Using existing executor");
|
||||
updateExecutionState();
|
||||
}
|
||||
|
||||
|
|
@ -132,6 +135,8 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
ActionBar actionBar = getActionBar();
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
action_execute = (MenuItem) menu.findItem(R.id.action_execute);
|
||||
updateExecutionState();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -144,6 +149,18 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_execute) {
|
||||
if(currentExecutor.isRunning()) {
|
||||
currentExecutor.terminate();
|
||||
csvLogger = null;
|
||||
}
|
||||
else {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if(prefs.getBoolean("logging", true))
|
||||
csvLogger = new CSVWriter(this);
|
||||
else
|
||||
csvLogger = null;
|
||||
currentExecutor.execute();
|
||||
}
|
||||
updateExecutionState();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -164,19 +181,11 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
}
|
||||
|
||||
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);
|
||||
if(action_execute != null) {
|
||||
if (currentExecutor.isRunning())
|
||||
action_execute.setTitle(R.string.action_stop);
|
||||
else
|
||||
csvLogger = null;
|
||||
currentExecutor.execute();
|
||||
action_execute.setTitle(R.string.action_stop);
|
||||
action_execute.setTitle(R.string.action_run);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -184,6 +193,10 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
@Override
|
||||
public void onBackPressed() {
|
||||
if (backButtonPressed) {
|
||||
if(currentExecutor != null){
|
||||
log.info("Terminating executor");
|
||||
currentExecutor.terminate();
|
||||
}
|
||||
super.onBackPressed();
|
||||
return;
|
||||
}
|
||||
|
|
@ -200,8 +213,6 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void logThroughput(double downThroughput, double upThroughput) {
|
||||
if(csvLogger == null || currentExecutor == null || currentExecutor.getRunningBehaviour() == null)
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue