mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
added checkboxes in the Phrasebook UI
This commit is contained in:
13
src/ui/android/res/layout/checkbox_input_list_item.xml
Normal file
13
src/ui/android/res/layout/checkbox_input_list_item.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="15sp"
|
||||
android:id="@+id/choice_checkbox" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -108,6 +108,9 @@ public class Model {
|
||||
} else if (node.getNodeName().equals("option")) {
|
||||
SyntaxNode[] options = constructSyntaxNodeList(node, ids, calls);
|
||||
return new SyntaxNodeOption(desc, options);
|
||||
} else if (node.getNodeName().equals("boolean")) {
|
||||
SyntaxNode[] options = constructSyntaxNodeList(node, ids, calls);
|
||||
return new SyntaxNodeBoolean(desc, options);
|
||||
} else if (node.getNodeName().equals("call")) {
|
||||
if (attributes.getNamedItem("ref") == null)
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package se.chalmers.phrasebook.backend.syntax;
|
||||
|
||||
public class SyntaxNodeBoolean extends SyntaxNodeOption {
|
||||
public SyntaxNodeBoolean(String desc, SyntaxNode[] options) {
|
||||
super(desc,options);
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,9 @@ public class TranslatorFragment extends Fragment {
|
||||
public View getView (int position, View convertView, ViewGroup parent) {
|
||||
SyntacticChoice choice = mContext.getChoices().get(position);
|
||||
View view = null;
|
||||
if (choice.getNode() instanceof SyntaxNodeOption) {
|
||||
if (choice.getNode() instanceof SyntaxNodeBoolean) {
|
||||
view = createCheckBoxInputView(inflater, choice, (SyntaxNodeBoolean) choice.getNode(), parent);
|
||||
} else if (choice.getNode() instanceof SyntaxNodeOption) {
|
||||
view = createSpinnerInputView(inflater, choice, (SyntaxNodeOption) choice.getNode(), parent);
|
||||
} else if (choice.getNode() instanceof SyntaxNodeNumeral) {
|
||||
view = createNumeralInputView(inflater, choice, (SyntaxNodeNumeral) choice.getNode(), parent);
|
||||
@@ -215,6 +217,31 @@ public class TranslatorFragment extends Fragment {
|
||||
return view;
|
||||
}
|
||||
|
||||
private View createCheckBoxInputView(LayoutInflater inflater, final SyntacticChoice choice, final SyntaxNodeBoolean options, ViewGroup parent) {
|
||||
View view = inflater.inflate(R.layout.checkbox_input_list_item, parent, false);
|
||||
final CheckBox checkBox = (CheckBox) view.findViewById(R.id.choice_checkbox);
|
||||
|
||||
String label = options.getDesc();
|
||||
if (label != null && !label.isEmpty()) {
|
||||
checkBox.setText(label);
|
||||
}
|
||||
|
||||
checkBox.setChecked(choice.getChoice() == 1);
|
||||
checkBox.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int position = checkBox.isChecked() ? 1 : 0;
|
||||
if (position != choice.getChoice()) {
|
||||
choice.setChoice(position);
|
||||
updateSyntax();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
public void updateSyntax() {
|
||||
mContext.reset();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user