Added basic configuration
This commit is contained in:
parent
b305095ab3
commit
1aec61f810
3 changed files with 69 additions and 18 deletions
|
|
@ -5,19 +5,22 @@ import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import com.ericsson.uecontrol.R;
|
import com.ericsson.uecontrol.R;
|
||||||
import com.ericsson.uecontrol.core.UeBehaviour;
|
import com.ericsson.uecontrol.core.UeBehaviour;
|
||||||
import com.ericsson.uecontrol.core.UeControlExecutor;
|
import com.ericsson.uecontrol.core.UeControlExecutor;
|
||||||
|
import com.ericsson.uecontrol.gui.fragments.ConfigureBehaviourDialog;
|
||||||
import com.ericsson.uecontrol.gui.fragments.SelectBehaviourDialog;
|
import com.ericsson.uecontrol.gui.fragments.SelectBehaviourDialog;
|
||||||
import com.ericsson.uecontrol.gui.util.BehaviourListAdapter;
|
import com.ericsson.uecontrol.gui.util.BehaviourListAdapter;
|
||||||
|
import com.ericsson.uecontrol.gui.util.Configurator;
|
||||||
import com.ericsson.uecontrol.gui.util.DynamicListView;
|
import com.ericsson.uecontrol.gui.util.DynamicListView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class EditActivity extends ListActivity implements View.OnClickListener {
|
public class EditActivity extends ListActivity implements AdapterView.OnItemClickListener {
|
||||||
private UeControlExecutor executor;
|
private UeControlExecutor executor;
|
||||||
private BehaviourListAdapter adapter;
|
private BehaviourListAdapter adapter;
|
||||||
|
|
||||||
|
|
@ -41,7 +44,7 @@ public class EditActivity extends ListActivity implements View.OnClickListener {
|
||||||
DynamicListView listView = (DynamicListView) findViewById(android.R.id.list);
|
DynamicListView listView = (DynamicListView) findViewById(android.R.id.list);
|
||||||
listView.setAdapter(adapter);
|
listView.setAdapter(adapter);
|
||||||
listView.setActionListener(adapter);
|
listView.setActionListener(adapter);
|
||||||
listView.setOnClickListener(this);
|
listView.setOnItemClickListener(this);
|
||||||
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,9 +82,13 @@ public class EditActivity extends ListActivity implements View.OnClickListener {
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||||
|
final UeBehaviour behaviour = executor.getBehaviourList().get(i);
|
||||||
|
Configurator confer = new Configurator(behaviour);
|
||||||
|
|
||||||
|
ConfigureBehaviourDialog dialog = new ConfigureBehaviourDialog();
|
||||||
|
dialog.setConfigurator(confer);
|
||||||
|
dialog.show(getFragmentManager(), "behaviour_configurator");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,14 @@ import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.ericsson.uecontrol.R;
|
import com.ericsson.uecontrol.R;
|
||||||
|
import com.ericsson.uecontrol.gui.util.Configurator;
|
||||||
|
import com.ericsson.uecontrol.gui.util.Configurator.ConfigurationParam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by ezivkoc on 2014-07-24.
|
* Created by ezivkoc on 2014-07-24.
|
||||||
*/
|
*/
|
||||||
public class ConfigureBehaviourDialog extends DialogFragment {
|
public class ConfigureBehaviourDialog extends DialogFragment {
|
||||||
|
private Configurator confer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
|
@ -22,24 +25,52 @@ public class ConfigureBehaviourDialog extends DialogFragment {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
builder.setTitle(R.string.configure_behaviour);
|
builder.setTitle(R.string.configure_behaviour);
|
||||||
|
|
||||||
|
LinearLayout root = new LinearLayout(getActivity());
|
||||||
|
root.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
root.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT));
|
||||||
|
|
||||||
|
for(ConfigurationParam confParam : confer.getConfiguration()){
|
||||||
|
LinearLayout layout = new LinearLayout(getActivity());
|
||||||
|
layout.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
layout.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||||
|
|
||||||
|
TextView label = new TextView(getActivity());
|
||||||
|
label.setText("Test: ");
|
||||||
|
label.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||||
|
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||||
|
layout.addView(label);
|
||||||
|
|
||||||
|
EditText input = new EditText(getActivity());
|
||||||
|
label.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT));
|
||||||
|
layout.addView(input);
|
||||||
|
|
||||||
|
root.addView(layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
builder.setPositiveButton(R.string.action_save, new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(R.string.action_save, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
// User clicked OK button
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() {
|
builder.setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {}
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
ConfigureBehaviourDialog.this.getDialog().cancel();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
LinearLayout root = new LinearLayout(getActivity());
|
|
||||||
|
|
||||||
LinearLayout param = new LinearLayout(getActivity());
|
|
||||||
param.addView(new TextView(getActivity()));
|
|
||||||
param.addView(new EditText(getActivity()));
|
|
||||||
root.addView(param);
|
|
||||||
|
|
||||||
builder.setView(root);
|
builder.setView(root);
|
||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setConfigurator(Configurator c) {
|
||||||
|
confer = c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,23 @@ public class Configurator {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static ConfigurationParam[] getConfiguration(Class c){
|
private Object obj;
|
||||||
|
private ConfigurationParam[] params;
|
||||||
|
|
||||||
|
public Configurator(Object obj){
|
||||||
|
this.obj = obj;
|
||||||
|
this.params = getConfiguration(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationParam[] getConfiguration(){
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static ConfigurationParam[] getConfiguration(Object obj){
|
||||||
|
Class c = obj.getClass();
|
||||||
ArrayList<ConfigurationParam> conf = new ArrayList<ConfigurationParam>();
|
ArrayList<ConfigurationParam> conf = new ArrayList<ConfigurationParam>();
|
||||||
|
|
||||||
Field[] all = c.getFields();
|
Field[] all = c.getDeclaredFields();
|
||||||
for(Field f : all){
|
for(Field f : all){
|
||||||
if(f.isAnnotationPresent(Configurable.class) && !Modifier.isStatic(f.getModifiers())) {
|
if(f.isAnnotationPresent(Configurable.class) && !Modifier.isStatic(f.getModifiers())) {
|
||||||
ConfigurationParam confParam = new ConfigurationParam();
|
ConfigurationParam confParam = new ConfigurationParam();
|
||||||
|
|
@ -52,10 +65,10 @@ public class Configurator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (ConfigurationParam[])conf.toArray();
|
return conf.toArray(new ConfigurationParam[conf.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setConfiguration(ConfigurationParam[] params, Object obj){
|
protected static void setConfiguration(ConfigurationParam[] params, Object obj){
|
||||||
for(ConfigurationParam param : params){
|
for(ConfigurationParam param : params){
|
||||||
try {
|
try {
|
||||||
param.field.setAccessible(true);
|
param.field.setAccessible(true);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue