ue-control/app/src/main/java/com/ericsson/uecontrol/gui/MainActivity.java

124 lines
4.6 KiB
Java
Raw Normal View History

2014-07-25 13:42:36 +02:00
package com.ericsson.uecontrol.gui;
import android.app.ActionBar;
import android.app.FragmentManager;
import android.content.Intent;
2014-07-31 09:53:04 +02:00
import android.content.SharedPreferences;
2014-07-25 13:42:36 +02:00
import android.os.Bundle;
2014-07-31 09:53:04 +02:00
import android.preference.PreferenceManager;
2014-07-25 13:42:36 +02:00
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;
import com.ericsson.uecontrol.R;
import com.ericsson.uecontrol.core.UeControlExecutor;
import com.ericsson.uecontrol.core.behaviour.UeBehaviourFtp;
2014-07-25 13:42:36 +02:00
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.NavigationDrawerFragment;
import com.ericsson.uecontrol.gui.fragments.StatusFragment;
2014-07-31 09:53:04 +02:00
import com.ericsson.uecontrol.gui.util.CSVWriter;
2014-07-25 13:42:36 +02:00
public class MainActivity extends FragmentActivity {
2014-07-25 13:42:36 +02:00
/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/
private NavigationDrawerFragment navigationDrawerFragment;
private StatusFragment statusFragment;
2014-07-31 09:53:04 +02:00
private static UeControlExecutor currentExecutor;
private static CSVWriter logger;
2014-07-25 13:42:36 +02:00
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
2014-07-31 09:53:04 +02:00
//navigationDrawerFragment = (NavigationDrawerFragment)
// getFragmentManager().findFragmentById(R.id.navigation_drawer);
2014-07-25 13:42:36 +02:00
statusFragment = (StatusFragment)
getFragmentManager().findFragmentById(R.id.status_fragment);
getFragmentManager().beginTransaction()
.replace(R.id.container, BehaviourListFragment.newInstance()).commit();
2014-07-25 13:42:36 +02:00
// Set up the drawer.
2014-07-31 09:53:04 +02:00
//navigationDrawerFragment.setUp(
// R.id.navigation_drawer,
// (DrawerLayout) findViewById(R.id.drawer_layout));
currentExecutor = new UeControlExecutor();
currentExecutor.addBehaviour(new UeBehaviourSleep());
currentExecutor.addBehaviour(new UeBehaviourSurfing());
currentExecutor.addBehaviour(new UeBehaviourSleep(4000));
currentExecutor.setThroughputListener(statusFragment.getThroughputListener());
2014-07-25 13:42:36 +02:00
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
2014-07-31 09:53:04 +02:00
if (navigationDrawerFragment == null || !navigationDrawerFragment.isDrawerOpen()) {
2014-07-25 13:42:36 +02:00
// Only show items in the action bar relevant to this screen
// if the drawer is not showing. Otherwise, let the drawer
// decide what to show in the action bar.
getMenuInflater().inflate(R.menu.main, menu);
2014-07-29 12:04:55 +02:00
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
2014-07-25 13:42:36 +02:00
return true;
}
return super.onCreateOptionsMenu(menu);
}
2014-07-29 12:04:55 +02:00
2014-07-25 13:42:36 +02:00
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_execute) {
2014-07-31 09:53:04 +02:00
if(currentExecutor.isRunning()){
currentExecutor.terminate();
2014-07-25 13:42:36 +02:00
item.setTitle(R.string.action_run);
}
else {
2014-07-31 09:53:04 +02:00
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(prefs.getBoolean("logging", false))
logger = new CSVWriter(this);
else
logger = null;
currentExecutor.execute();
2014-07-25 13:42:36 +02:00
item.setTitle(R.string.action_stop);
}
return true;
}
if (id == R.id.action_edit) {
Intent intent = new Intent(this, EditActivity.class);
startActivity(intent);
return true;
}
if (id == R.id.action_settings) {
startActivity(new Intent(this, SettingsActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
2014-07-31 09:53:04 +02:00
public static UeControlExecutor getExecutor() {
return currentExecutor;
}
public static void logThroughput(double downThroughput, double upThroughput) {
if(logger == null || currentExecutor == null || currentExecutor.getRunningBehaviour() == null)
return;
logger.write(currentExecutor.getRunningBehaviour().getName(), downThroughput, upThroughput);
2014-07-25 13:42:36 +02:00
}
}