Intro
I’m currently developing an OF app and want to use the menu/dialog system of Android to adjust some settings of the application. These settings should be forwarded to OF (C++).
Implementation
For now I have implemented a Menu and View for the popup Dialog in XML. When the users presses the menu button, it will show the menubar:
After selecting one of the example options, it will open up a new dialog (on top of the current OF Activity):
In the Java part (OFActivity.java) I have the following method that is called when the dialog is created:
private AlertDialog getDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
final View myView = inflater.inflate(R.layout.settings, null);
final SeekBar ExampleSeekBar = (SeekBar)myView.findViewById(R.id.ExampleSeekBar);
ExampleSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Store/set values
Log.d("OFUI", "ExampleSeekBar: " + seekBar.getProgress());
}
public void onStartTrackingTouch(SeekBar ExampleSeekBar) { }
public void onStopTrackingTouch(SeekBar seekBar) { }
});
final CheckBox ExampleCheckbox = (CheckBox)myView.findViewById(R.id.ExampleCheckbox);
builder.setTitle("Settings")
.setView(myView)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Log.d("OFUI", "getDialog - OK");
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Log.d("OFUI", "getDialog - Cancel");
dialog.cancel();
}
});
AlertDialog alert = builder.create();
return alert;
}
This code uses the LayoutInflater to load the view made in XML. It also binds a SeekBarChangeListener and outputs the changes in realtime to logcat.
The question
Instead of getting the values in logcat, I would like to use these values directly in the OF app. How would I do this? I have checked the methods ofxAndroidApp but none of them seem to be useful for passing values from the UI to the C++ app. menuItemSelected for example only tells me which menu item is selected (which is not useful in my case)
The only thing I can think of would be adding additional/custom JNI methods. But before doing that, I would like to know if there is another method I can use instead.
Full sourcecode menu demo
http://falcon4ever.pcsx2.net/androidEmptyExampleMenus.7z