added checkboxes in the Phrasebook UI

This commit is contained in:
krasimir
2016-06-03 11:09:39 +00:00
parent eb6058b517
commit 8a3c86ac1d
4 changed files with 51 additions and 1 deletions

View 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>

View File

@@ -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;

View File

@@ -0,0 +1,7 @@
package se.chalmers.phrasebook.backend.syntax;
public class SyntaxNodeBoolean extends SyntaxNodeOption {
public SyntaxNodeBoolean(String desc, SyntaxNode[] options) {
super(desc,options);
}
}

View File

@@ -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();