2014-07-31 15:01:44 +02:00
|
|
|
package com.ericsson.uecontrol.gui;
|
|
|
|
|
|
|
|
|
|
import android.app.ListActivity;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.view.Menu;
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
|
import android.widget.ListView;
|
|
|
|
|
|
|
|
|
|
import com.ericsson.uecontrol.R;
|
|
|
|
|
import com.ericsson.uecontrol.core.UeBehaviour;
|
|
|
|
|
import com.ericsson.uecontrol.core.UeControlExecutor;
|
|
|
|
|
import com.ericsson.uecontrol.gui.fragments.ConfigureDialog;
|
|
|
|
|
import com.ericsson.uecontrol.gui.fragments.SelectBehaviourDialog;
|
|
|
|
|
import com.ericsson.uecontrol.gui.util.BehaviourListAdapter;
|
|
|
|
|
import com.ericsson.uecontrol.gui.util.DynamicListView;
|
|
|
|
|
|
2014-08-01 16:07:48 +02:00
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
|
2014-08-04 15:36:45 +02:00
|
|
|
import java.io.File;
|
2014-07-31 15:01:44 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class EditActivity extends ListActivity implements AdapterView.OnItemClickListener {
|
2014-08-01 16:07:48 +02:00
|
|
|
private static final Logger log = Logger.getLogger(EditActivity.class);
|
|
|
|
|
|
2014-07-31 15:01:44 +02:00
|
|
|
private UeControlExecutor executor;
|
|
|
|
|
private BehaviourListAdapter adapter;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
setContentView(R.layout.activity_edit);
|
|
|
|
|
|
|
|
|
|
final List<UeBehaviour> list;
|
|
|
|
|
executor = MainActivity.getExecutor();
|
|
|
|
|
list = executor.getBehaviourList();
|
|
|
|
|
|
|
|
|
|
adapter = new BehaviourListAdapter(this, list);
|
|
|
|
|
adapter.setEditable(true);
|
|
|
|
|
DynamicListView listView = (DynamicListView) findViewById(android.R.id.list);
|
|
|
|
|
listView.setAdapter(adapter);
|
|
|
|
|
listView.setActionListener(adapter);
|
|
|
|
|
listView.setOnItemClickListener(this);
|
|
|
|
|
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
|
getMenuInflater().inflate(R.menu.edit, menu);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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_add) {
|
|
|
|
|
SelectBehaviourDialog selector = new SelectBehaviourDialog();
|
|
|
|
|
selector.setSelectionCallback(new SelectBehaviourDialog.BehaviourSelectionCallback() {
|
|
|
|
|
public void behaviourSelected(String name, Class<UeBehaviour> objClass) {
|
|
|
|
|
try {
|
|
|
|
|
UeBehaviour obj = objClass.newInstance();
|
|
|
|
|
executor.addBehaviour(obj);
|
|
|
|
|
adapter.generateIds();
|
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
|
} catch (Exception e) {
|
2014-08-01 16:07:48 +02:00
|
|
|
log.warn(null, e);
|
2014-07-31 15:01:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
selector.show(getFragmentManager(), "behaviour_selector");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-08-19 17:56:12 +02:00
|
|
|
else if (id == R.id.action_clear) {
|
|
|
|
|
executor.getBehaviourList().clear();
|
2015-01-15 15:59:37 +01:00
|
|
|
adapter.generateIds();
|
2014-08-19 17:56:12 +02:00
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-07-31 15:01:44 +02:00
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
|
|
UeBehaviour behaviour = executor.getBehaviourList().get(i);
|
|
|
|
|
|
2014-08-04 16:18:59 +02:00
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
|
bundle.putInt("object_index", i);
|
2014-07-31 15:01:44 +02:00
|
|
|
ConfigureDialog dialog = new ConfigureDialog();
|
2014-08-04 16:18:59 +02:00
|
|
|
dialog.setArguments(bundle);
|
2014-07-31 15:01:44 +02:00
|
|
|
dialog.show(getFragmentManager(), "behaviour_configurator");
|
|
|
|
|
}
|
2014-08-04 15:36:45 +02:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onPause() {
|
|
|
|
|
try {
|
|
|
|
|
File input = new File(this.getFilesDir(), MainActivity.BEHAVIOUR_SAVE_FILE);
|
|
|
|
|
executor.save(input.getAbsolutePath());
|
|
|
|
|
log.debug("Saved current state");
|
2014-08-06 17:01:01 +02:00
|
|
|
log.debug("Resetting executor");
|
|
|
|
|
executor.reset();
|
2014-08-04 15:36:45 +02:00
|
|
|
}catch(Exception e){log.error(null, e);}
|
|
|
|
|
super.onPause();
|
|
|
|
|
}
|
2014-08-05 12:55:51 +02:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
|
super.onResume();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-31 15:01:44 +02:00
|
|
|
}
|