87 lines
3 KiB
Java
Executable file
87 lines
3 KiB
Java
Executable file
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.ListView;
|
|
|
|
import com.ericsson.uecontrol.R;
|
|
import com.ericsson.uecontrol.core.UeBehaviour;
|
|
import com.ericsson.uecontrol.core.UeControlExecutor;
|
|
import com.ericsson.uecontrol.gui.fragments.SelectBehaviourDialog;
|
|
import com.ericsson.uecontrol.gui.util.BehaviourListAdapter;
|
|
import com.ericsson.uecontrol.gui.util.DynamicListView;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class EditActivity extends ListActivity implements View.OnClickListener {
|
|
private UeControlExecutor executor;
|
|
private BehaviourListAdapter adapter;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_edit);
|
|
|
|
final List<UeBehaviour> list;
|
|
if(getIntent().hasExtra("executor")) {
|
|
int executorIndex = getIntent().getExtras().getInt("executor_index");
|
|
executor = MainActivity.getExecutor(executorIndex);
|
|
|
|
list = executor.getBehaviourList();
|
|
}
|
|
else
|
|
list = new ArrayList<UeBehaviour>();
|
|
|
|
adapter = new BehaviourListAdapter(this, list);
|
|
adapter.setEditable(true);
|
|
DynamicListView listView = (DynamicListView) findViewById(android.R.id.list);
|
|
listView.setAdapter(adapter);
|
|
listView.setActionListener(adapter);
|
|
listView.setOnClickListener(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) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
});
|
|
selector.show(getFragmentManager(), "behaviour_selector");
|
|
return true;
|
|
}
|
|
return super.onOptionsItemSelected(item);
|
|
}
|
|
|
|
|
|
@Override
|
|
public void onClick(View view) {
|
|
|
|
}
|
|
}
|