Added state saving
This commit is contained in:
parent
e020204ce5
commit
580f4fdc3d
7 changed files with 56 additions and 12 deletions
|
|
@ -32,6 +32,8 @@ import de.mindpipe.android.logging.log4j.LogConfigurator;
|
|||
public class MainActivity extends FragmentActivity implements OnSharedPreferenceChangeListener{
|
||||
private static final Logger log = Logger.getLogger(MainActivity.class);
|
||||
public static final String DEFAULT_LOG_PATH = "/sdcard/uecontrol/";
|
||||
public static final String BEHAVIOUR_SAVE_FILE = "behaviour_list.dat";
|
||||
|
||||
|
||||
/** Fragments **/
|
||||
private StatusFragment statusFragment;
|
||||
|
|
@ -57,12 +59,23 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
|
||||
|
||||
currentExecutor = new UeControlExecutor();
|
||||
currentExecutor.addBehaviour(new UeBehaviourSleep());
|
||||
currentExecutor.addBehaviour(new UeBehaviourSurfing());
|
||||
currentExecutor.addBehaviour(new UeBehaviourSleep(4000));
|
||||
currentExecutor.setThroughputListener(statusFragment.getThroughputListener());
|
||||
File input = new File(this.getFilesDir(), BEHAVIOUR_SAVE_FILE);
|
||||
if(input.exists()) {
|
||||
try {
|
||||
log.debug("Reading saved state");
|
||||
currentExecutor.read(input.getAbsolutePath());
|
||||
}catch(Exception 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setupDebugLogging(){
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String path = prefs.getString("logging_path", DEFAULT_LOG_PATH);
|
||||
|
|
@ -133,12 +146,12 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
}
|
||||
return true;
|
||||
}
|
||||
if (id == R.id.action_edit) {
|
||||
else if (id == R.id.action_edit) {
|
||||
Intent intent = new Intent(this, EditActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
if (id == R.id.action_settings) {
|
||||
else if (id == R.id.action_settings) {
|
||||
startActivity(new Intent(this, SettingsActivity.class));
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue