Added option for device or app level throughput.

Started on a file browser dialog for import/export
This commit is contained in:
Ziver Koc 2014-08-15 16:05:56 +02:00
parent 01896c15e5
commit 9f84e472eb
6 changed files with 80 additions and 29 deletions

View file

@ -19,6 +19,7 @@ import com.ericsson.uecontrol.core.UeControlExecutor;
import com.ericsson.uecontrol.core.behaviour.UeBehaviourSleep;
import com.ericsson.uecontrol.core.behaviour.UeBehaviourSurfing;
import com.ericsson.uecontrol.gui.fragments.BehaviourListFragment;
import com.ericsson.uecontrol.gui.fragments.FileBrowserDialog;
import com.ericsson.uecontrol.gui.fragments.StatusFragment;
import com.ericsson.uecontrol.gui.util.CSVWriter;
@ -51,8 +52,12 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set static fields
// Set static fields and preferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
prefs.registerOnSharedPreferenceChangeListener(this);
uid = getApplicationInfo().uid;
context = this;
@ -66,10 +71,11 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
getFragmentManager().beginTransaction()
.replace(R.id.container, new BehaviourListFragment()).commit();
// Setup Executor
if(currentExecutor == null) {
log.info("Creating new instance of executor");
currentExecutor = new UeControlExecutor();
currentExecutor.setDeviceBasedThroughput(Boolean.parseBoolean(prefs.getString("throughput_type", "false")));
File input = new File(this.getFilesDir(), BEHAVIOUR_SAVE_FILE);
if (input.exists()) {
try {
@ -91,6 +97,9 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
}
currentExecutor.setThroughputListener(statusFragment.getThroughputListener());
updateExecutionState();
}
@ -109,8 +118,6 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
// Set log level of a specific logger
logConfigurator.setLevel("org.apache", Level.ERROR);
logConfigurator.configure();
prefs.registerOnSharedPreferenceChangeListener(this);
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
@ -124,6 +131,11 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
Logger.getRootLogger().setLevel(Level.WARN);
}
}
else if(key.equals("throughput_type")){
log.info("Device Throughput set to: "+sharedPreferences.getString("throughput_type", "false"));
if(currentExecutor != null)
currentExecutor.setDeviceBasedThroughput(Boolean.parseBoolean(sharedPreferences.getString("throughput_type", "false")));
}
}
@ -190,6 +202,12 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
Toast.makeText(this, "Stop execution to edit behaviours", Toast.LENGTH_SHORT).show();
return true;
}
else if (id == R.id.action_import) {
//TODO:
}
else if (id == R.id.action_export) {
//TODO:
}
else if (id == R.id.action_settings) {
startActivity(new Intent(this, SettingsActivity.class));
return true;
@ -197,6 +215,7 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
return super.onOptionsItemSelected(item);
}
private void updateExecutionState(){
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(action_execute != null) {
@ -253,5 +272,4 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
return uid;
}
public static Context getContext(){return context;}
}