add the relevant code from Parlira to the GFTranslator

This commit is contained in:
krasimir
2016-05-23 09:54:27 +00:00
parent 67998b1d1a
commit a8f50098d3
38 changed files with 2863 additions and 1 deletions

View File

@@ -44,6 +44,9 @@
<meta-data android:name="android.app.default_searchable"
android:value=".SearchableActivity"/>
</activity>
<activity android:name="se.chalmers.phrasebook.gui.activities.NavigationActivity"></activity>
<service android:name="TranslatorInputMethodService"
android:permission="android.permission.BIND_INPUT_METHOD">
<intent-filter>

View File

@@ -0,0 +1,642 @@
<?xml version="1.0" encoding="UTF-8"?>
<phrasebook>
<!--works-->
<sentence desc="What is somebody's name?" id="QWhatName">
<node syntax="PQuestion">
<node syntax="QWhatName">
<option option="Who are we talking about?">
<node child="allpersons" />
</option>
</node>
</node>
</sentence>
<!--SOMETHING IS UP WITH THE NAMEPARSING; WE CAN TRANSLATE ONCE BUT NOT INITIALIZE-->
<sentence desc="Somebody's name is..." id="AHasName">
<node child="phraseit">
<node syntax="PropAction">
<node args="2" syntax="AHasName">
<option option="Who are we talking about?">
<node child="allpersons"></node>
</option>
<node syntax="NameNN" />
</node>
</node>
</node>
</sentence>
<!--works-->
<sentence desc="How old is someone?" id="QWhatAge">
<node syntax="PQuestion">
<node syntax="QWhatAge">
<option option="Who are we talking about?">
<node child="allpersons" />
</option>
</node>
</node>
</sentence>
<sentence desc="Someone's age is..." id="AHasAge">
<node child="phraseit">
<node syntax="PropAction">
<node args="2" syntax="AHasAge">
<option option="Who are we talking about?">
<node child="allpersons" />
</option>
<option option="How many years?">
<node syntax="NNumeral" />
</option>
</node>
</node>
</node>
</sentence>
<!--<sentence desc="Numbers" id="NNumeral">
<node syntax="">
<option option="Which number?">
<node syntax="NNumeral"/>
</option>
</node>
</sentence>-->
<advanced desc="Reported Speech" id="AKnowQuestion">
<node child="advphraseit">
<node syntax="PropAction">
<node syntax="AKnow">
<option option="Who is saying they know this?">
<node child="allpersons" />
</option>
</node>
</node>
</node>
</advanced>
<!--works-->
<sentence advanced="true" desc="Someone loves someone" id="ALove">
<node child="phraseit">
<node syntax="PropAction">
<node args="2" syntax="ALove">
<option option="Who loves someone?">
<node child="allpersons"></node>
</option>
<option option="Who is loved?">
<node child="allpersons"></node>
</option>
</node>
</node>
</node>
</sentence>
<!--works-->
<sentence advanced="true" desc="Someone is married" id="AMarried">
<node child="phraseit">
<node syntax="PropAction">
<node syntax="AMarried">
<option option="Who are we talking about?">
<node child="allpersons" />
</option>
</node>
</node>
</node>
</sentence>
<!--works-->
<sentence desc="Someone is hungry" id="AHungry">
<node child="phraseit">
<node syntax="PropAction">
<node syntax="AHungry">
<option option="Who are we talking about?">
<node child="allpersons" />
</option>
</node>
</node>
</node>
</sentence>
<!--works-->
<sentence advanced="true" desc="Someone is thirsty" id="AThirsty">
<node child="phraseit">
<node syntax="PropAction">
<node syntax="AThirsty">
<option option="Who are we talking about?">
<node child="allpersons" />
</option>
</node>
</node>
</node>
</sentence>
<!--works-->
<sentence desc="Someone is tired" id="ATired">
<node child="phraseit">
<node syntax="PropAction">
<node syntax="ATired">
<option option="Who are we talking about?">
<node child="allpersons" />
</option>
</node>
</node>
</node>
</sentence>
<!-- works-->
<sentence desc="Someone is scared" id="AScared">
<node child="phraseit">
<node syntax="PropAction">
<node syntax="AScared">
<option option="Who are we talking about?">
<node child="allpersons"></node>
</option>
</node>
</node>
</node>
</sentence>
<!--WORKS-->
<sentence desc="Someone is ill" id="AIll">
<node child="phraseit">
<node syntax="PropAction">
<node syntax="AIll">
<option option="Who are we talking about?">
<node child="allpersons"></node>
</option>
</node>
</node>
</node>
</sentence>
<!--WORKS-->
<sentence desc="Someone understands" id="AUnderstand">
<node child="phraseit">
<node syntax="PropAction">
<node syntax="AUnderstand">
<option option="Who are we talking about?">
<node child="allpersons"></node>
</option>
</node>
</node>
</node>
</sentence>
<!--WORKS-->
<sentence desc="Someone knows" id="AKnow">
<node child="phraseit">
<node syntax="PropAction">
<node syntax="AKnow">
<option option="Who are we talking about?">
<node child="allpersons"></node>
</option>
</node>
</node>
</node>
</sentence>
<!--WORKS-->
<sentence desc="Someone is ready" id="AReady">
<node child="phraseit">
<node syntax="PropAction">
<node syntax="AReady">
<option option="Who are we talking about?">
<node child="allpersons"></node>
</option>
</node>
</node>
</node>
</sentence>
<sentence desc="Someone speaks a language" id="ASpeak">
<node child="phraseit">
<node syntax="PropAction">
<node args="2" syntax="ASpeak">
<option option="Who speaks it?">
<node child="allpersons"></node>
</option>
<option option="What language?">
<node child="language" />
</option>
</node>
</node>
</node>
</sentence>
<!--WORKS-->
<sentence desc="How far is something?" id="HowFar">
<node syntax="PQuestion">
<node syntax="HowFar">
<option option="What place are we asking about?">
<node child="superlative_places" />
</option>
</node>
</node>
</sentence>
<!--WORKS-->
<sentence desc="Someone has children" id="AHasChildren">
<node child="phraseit">
<node syntax="PropAction">
<node args="2" syntax="AHasChildren">
<option option="Who are we talking about?">
<node child="allpersons"></node>
</option>
<option option="How many children?">
<node syntax="NNumeral" />
</option>
</node>
</node>
</node>
</sentence>
<!--WORKS-->
<sentence desc="Someone lives somewhere" id="ALive">
<node child="phraseit">
<node syntax="PropAction">
<node args="2" syntax="ALive">
<option option="Who are we talking about?">
<node child="allpersons"></node>
</option>
<option option="Living where?">
<node child="country"></node>
</option>
</node>
</node>
</node>
</sentence>
<!-- Works-->
<sentence desc="Someone wants to go somewhere" id="AWantGo">
<node child="phraseit">
<node syntax="PropAction">
<node args="2" syntax="AWantGo">
<option option="Who are we talking about?">
<node child="allpersons"></node>
</option>
<option option="What article?">
<node child="a/an/the">
<option option="What place?">
<node child="places"></node>
</option>
</node>
</option>
</node>
</node>
</node>
</sentence>
<!--Works-->
<sentence desc="Someone is somewhere" id="ABePlace">
<node child="phraseit">
<node syntax="PropAction">
<node args="2" syntax="ABePlace">
<option option="Who are we talking about?">
<node child="allpersons"></node>
</option>
<option option="What article?">
<node child="a/an/the">
<option option="What place?">
<node child="places"></node>
</option>
</node>
</option>
</node>
</node>
</node>
</sentence>
<!-- Someone is somewhere -->
<!-- ASK KRASIMIR-->
<sentence desc="How far is something from somewhere?" id="HowFarFrom">
<node syntax="PQuestion">
<node args="2" syntax="HowFarFrom">
<option option="Where are we going from?">
<node child="superlative_places" />
</option>
<option option="Where are we going to?">
<node child="superlative_places" />
</option>
</node>
</node>
</sentence>
<!--WORKS-->
<sentence desc="Some place is open" id="PropOpen">
<node child="phraseit">
<node syntax="PropOpen">
<node args="2" syntax=" ">
<option option="Superlative">
<node child="superlative" />
</option>
<option option="What place are we asking about?">
<node child="places" />
</option>
</node>
</node>
</node>
</sentence>
<!--WORKS-->
<sentence desc="Some place is closed" id="PropClosed">
<node child="phraseit">
<node syntax="PropClosed">
<node args="2" syntax=" ">
<option option="Superlative">
<node child="superlative" />
</option>
<option option="What place are we asking about?">
<node child="places" />
</option>
</node>
</node>
</node>
</sentence>
<!-- Kinda works-->
<sentence desc="Someone wants some food" id="AWant">
<node child="phraseit">
<node syntax="PropAction">
<node args="2" syntax="AWant">
<option option="Who wants food?">
<node child="allpersons"></node>
</option>
<node child="food_with_objectsPrep"></node>
</node>
</node>
</node>
</sentence>
<sentence desc="Someone likes some food" id="ALike">
<node child="phraseit">
<node syntax="PropAction">
<node args="2" syntax="ALike">
<option option="Who likes it?">
<node child="allpersons"></node>
</option>
<node child="prep">
<node child="food"></node>
</node>
</node>
</node>
</node>
</sentence>
<sentence desc="How much does something cost?" id="HowMuchCost">
<node syntax="PQuestion">
<node syntax="HowMuchCost">
<node child="prep">
<node child="food" />
</node>
</node>
</node>
</sentence>
<!-- ___________________________________________________________________________________________ -->
<!--Option lists -->
<child id="allpersons">
<node child="persons" />
<node child="familypersons" />
</child>
<child id="superlative_places">
<node child="superlative">
<option option="">
<node child="places"></node>
</option>
</node>
</child>
<child id="a/an/the">
<node desc="a/an" syntax="APlace">
<option option="">
<node syntax=" " />
</option>
</node>
<node desc="The" syntax=" ">
<option option=" ">
<node child="superlative" />
</option>
</node>
</child>
<child id="phraseit">
<option option="How do you want to phrase it?">
<node desc="As a statement" syntax="PSentence">
<node syntax="SProp"/>
</node>
<node desc="As a question" syntax="PQuestion">
<node syntax="QProp"/>
</node>
<node desc="As a negation" syntax="PSentence">
<node syntax="SPropNot"/>
</node>
</option>
</child>
<child id="advphraseit">
<option option="How are they phrasing it?">
<node desc="As a statement" syntax="PSentence">
<node syntax="SProp"></node>
</node>
<node desc="As a question" syntax="PQuestion">
<node syntax="QProp"></node>
</node>
<node desc="As a negation" syntax="PSentence">
<node syntax="SPropNot"></node>
</node>
</option>
</child>
<child id="language">
<option option="What language?">
<node desc="Bulgarian" syntax="(LangNat Bulgarian)" />
<node desc="Catalan" syntax="(LangNat Catalan)" />
<node desc="Danish" syntax="(LangNat Danish)" />
<node desc="Dutch" syntax="(LangNat Dutch)" />
<node desc="English" syntax="(LangNat English)" />
<node desc="Finnish" syntax="(LangNat Finnish)" />
<node desc="Flemish" syntax="Flemish" />
<node desc="French" syntax="(LangNat French)" />
<node desc="German" syntax="(LangNat German)" />
<node desc="Italian" syntax="(LangNat Italian)" />
<node desc="Norwegian" syntax="(LangNat Norwegian)" />
<node desc="Polish" syntax="(LangNat Polish)" />
<node desc="Romanian" syntax="(LangNat Romanian)" />
<node desc="Russian" syntax="(LangNat Russian)" />
<node desc="Spanish" syntax="(LangNat Spanish)" />
<node desc="Swedish" syntax="(LangNat Swedish)" />
</option>
</child>
<child id="nationality">
<option option="What nationality">
<node desc="Belgian" syntax="Belgian"></node>
<node desc="Bulgarian" syntax="CitiNat Bulgarian"></node>
<node desc="Catalan" syntax="CitiNat Catalan"></node>
<node desc="Dutch" syntax="CitiNat Dutch"></node>
<node desc="Danish" syntax="CitiNat Danish"></node>
<node desc="English" syntax="CitiNat English"></node>
<node desc="Finnish" syntax="CitiNat Finnish"></node>
<node desc="French" syntax="CitiNat French"></node>
<node desc="German" syntax="CitiNat German"></node>
<node desc="Italian" syntax="CitiNat Italian"></node>
<node desc="Norwegian" syntax="CitiNat Norwegian"></node>
<node desc="Polish" syntax="CitiNat Polish"></node>
<node desc="Romanian" syntax="CitiNat Romanian"></node>
<node desc="Russian" syntax="CitiNat Russian"></node>
<node desc="Spanish" syntax="CitiNat Spanish"></node>
<node desc="Swedish" syntax="CitiNat Swedish"></node>
</option>
</child>
<child id="places">
<node desc="supermarket" syntax="Supermarket"></node>
<node desc="bank" syntax="Bank"></node>
<node desc="amusement park" syntax="AmusementPark"></node>
<node desc="bar" syntax="Bar"></node>
<node desc="Cafeteria" syntax="Cafeteria"></node>
<node desc="car park" syntax="Parking"></node>
<node desc="center" syntax="Center"></node>
<node desc="cinema" syntax="Cinema"></node>
<node desc="church" syntax="Church"></node>
<node desc="disco" syntax="Disco"></node>
<node desc="hospital" syntax="Hospital"></node>
<node desc="hotel" syntax="Hotel"></node>
<node desc="museum" syntax="Museum"></node>
<node desc="park" syntax="Park"></node>
<node desc="pharmacy" syntax="Pharmacy"></node>
<node desc="post office" syntax="PostOffice"></node>
<node desc="pub" syntax="Pub"></node>
<!--<node desc="restaurant" syntax="CitRestaurant">
<node child="nationality"></node>
</node>-->
<node desc="school" syntax="School"></node>
<node desc="shop" syntax="Shop"></node>
</child>
<child id="superlative">
<node desc="(no superlative)" syntax="ThePlace"></node>
<node desc="best" syntax="SuperlPlace TheBest"></node>
<node desc="worst" syntax="SuperlPlace TheWorst"></node>
<node desc="nearest" syntax="SuperlPlace TheClosest"></node>
<node desc="cheapest" syntax="SuperlPlace TheCheapest"></node>
<node desc="most expensive" syntax="SuperlPlace TheMostExpensive"></node>
<node desc="most popular" syntax="SuperlPlace TheMostPopular"></node>
</child>
<child id="persons">
<node desc="me (male)" syntax="IMale" />
<node desc="me (female)" syntax="IFemale" />
<node desc="you (a male friend)" syntax="YouFamMale" />
<node desc="you (a female friend)" syntax="YouFamFemale" />
<node desc="you (a male stranger)" syntax="YouPolMale" />
<node desc="you (a female stranger)" syntax="YouPolFemale" />
</child>
<child id="familypersons">
<node desc="Wife of..." syntax="Wife">
<option option="">
<node child="persons" />
</option>
</node>
<node desc="Husband of..." syntax="Husband">
<option option="">
<node child="persons" />
</option>
</node>
<node desc="Daughter of..." syntax="Daughter">
<option option="">
<node child="persons" />
</option>
</node>
<node desc="Son of..." syntax="Son">
<option option="">
<node child="persons" />
</option>
</node>
<node desc="Children of..." syntax="Children">
<option option="">
<node child="persons" />
</option>
</node>
</child>
<child id="country">
<option option="What nationality">
<node desc="Belgium" syntax="Belgium"></node>
<node desc="Bulgaria" syntax="CountryNat Bulgarian"></node>
<node desc="Catalonia" syntax="CountryNat Catalan"></node>
<node desc="The Netherlands" syntax="CountryNat Dutch"></node>
<node desc="Denmark" syntax="CountryNat Danish"></node>
<node desc="England" syntax="CountryNat English"></node>
<node desc="Finland" syntax="CountryNat Finnish"></node>
<node desc="France" syntax="CountryNat French"></node>
<node desc="Germany" syntax="CountryNat German"></node>
<node desc="Italy" syntax="CountryNat Italian"></node>
<node desc="Norway" syntax="CountryNat Norwegian"></node>
<node desc="Poland" syntax="CountryNat Polish"></node>
<node desc="Romania" syntax="CountryNat Romanian"></node>
<node desc="Russia" syntax="CountryNat Russian"></node>
<node desc="Spain" syntax="CountryNat Spanish"></node>
<node desc="Sweden" syntax="CountryNat Swedish"></node>
</option>
</child>
<child id="food_with_objectsPrep">
<option option="What is being wanted?">
<node child="objectsPrep">
<node child="food"></node>
</node>
</option>
</child>
<child id="objectsPrep">
<node desc="a/an" syntax="OneObj">
<node syntax="ObjMass"></node>
</node>
<node desc="the" syntax="OneObj">
<node syntax="ObjItem">
<node syntax="TheMass"></node>
</node>
</node>
<node desc="this" syntax="OneObj">
<node syntax="ObjItem">
<node syntax="ThisMass"></node>
</node>
</node>
<node desc="that" syntax="OneObj">
<node syntax="ObjItem">
<node syntax="ThatMass"></node>
</node>
</node>
</child>
<child id="prep">
<option option="Preposition">
<node desc="The" syntax="TheMass" />
<node desc="This" syntax="ThisMass" />
<node desc="That" syntax="ThatMass" />
</option>
</child>
<child id="food">
<option option="What are we talking about?">
<node desc="Beer" syntax="MassDrink Beer"></node>
<node desc="Bread" syntax="Bread"></node>
<node desc="Cheese" syntax="Cheese"></node>
<node desc="Chicken" syntax="Chicken"></node>
<node desc="Coffee" syntax="MassDrink Coffee"></node>
<node desc="Fish" syntax="Fish"></node>
<node desc="Meat" syntax="Meat"></node>
<node desc="Milk" syntax="Milk"></node>
<node desc="Salt" syntax="Salt"></node>
<node desc="Tea" syntax="MassDrink Tea"></node>
<node desc="Water" syntax="MassDrink Water"></node>
<node desc="Wine" syntax="MassDrink Wine"></node>
</option>
</child>
</phrasebook>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="1dp"
android:color="@color/primary_color" />
<padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" />
<corners android:radius="8dp" />
</shape>

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

View File

@@ -0,0 +1,16 @@
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".gui.activities.NavigationActivity">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.DrawerLayout>

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="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Activate Advanced Options"
android:id="@+id/checkBox" />
</LinearLayout>

View File

@@ -0,0 +1,47 @@
<?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="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/containerfor_translation"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/containerfor_options"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dots"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_gravity="center|bottom">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/firstDot"
android:src="@drawable/ic_dictionary" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/secondDot"
android:src="@drawable/ic_dictionary" />
</LinearLayout>
</FrameLayout>
</LinearLayout>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textColor="@color/text_colour_light"
android:fontFamily="sans-serif-light"
android:text="New Text"
android:id="@+id/textView3"
android:padding="8dp"
xmlns:android="http://schemas.android.com/apk/res/android" />

View File

@@ -0,0 +1,16 @@
<?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="match_parent"
android:id="@+id/input_holder"
android:padding="8dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:textSize="25dp"
android:id="@+id/holderOptionText" />
</LinearLayout>

View File

@@ -0,0 +1,28 @@
<?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="match_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:textSize="15sp"
android:id="@+id/textView_number" />
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:id="@+id/seekBar" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberPassword"
android:ems="10"
android:id="@+id/editNumber" />
</LinearLayout>

View File

@@ -0,0 +1,59 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
tools:context=".gui.smallFragments.OptionsFragment"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/child_fragment1">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/child_fragment2">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/child_fragment3">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/child_fragment4">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/child_fragment5">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/child_fragment6">
</FrameLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

@@ -0,0 +1,20 @@
<?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="match_parent"
android:id="@+id/spinner_input">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:textSize="15sp"
android:id="@+id/text_view_spinner" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/choice_spinner" />
</LinearLayout>

View File

@@ -0,0 +1,15 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".gui.smallFragments.SwipeFragment"
android:id="@+id/fragment_swipe">
<android.support.v4.view.ViewPager
android:id="@+id/vpPager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
</FrameLayout>

View File

@@ -0,0 +1,45 @@
<?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"
android:background="@drawable/grid_phrasebook_button"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="@+id/fragment_translation">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:textSize="24dp"
android:id="@+id/origin_phrase"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:maxLines="4"
android:scrollHorizontally="false"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:textSize="24dp"
android:id="@+id/target_phrase"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:maxLines="4"
android:scrollHorizontally="false"
/>
<ImageView
android:id="@+id/button3"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="right"
android:src="@drawable/ic_volume_up_black_18dp"/>
</LinearLayout>

View File

@@ -1,6 +1,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/input_mode"
android:title="@string/keyboard_input"/>
<item android:id="@+id/phrasebook"
android:title="@string/phrasebook"/>
<item android:id="@+id/topics"
android:title="@string/topics"/>
<item android:id="@+id/help"

View File

@@ -4,4 +4,6 @@
<color name="candidate_recommended">#FFE35900</color>
<color name="candidate_other">#ff808080</color>
<color name="candidate_background">#ffffffff</color>
</resources>
<item name="primary_color" type="color">#009688</item>
<item name="text_colour_light" type="color">#616161</item>
</resources>

View File

@@ -33,4 +33,6 @@
<string name="topics">Topics</string>
<string name="topics_open">Open topics</string>
<string name="topics_close">Close topics</string>
<string name="phrasebook">Phrasebook</string>
</resources>

View File

@@ -4,13 +4,19 @@ import android.app.Application;
public class GFTranslator extends Application {
private Translator mTranslator;
private static GFTranslator instance;
@Override
public void onCreate() {
mTranslator = new Translator(this);
instance = this;
}
public Translator getTranslator() {
return mTranslator;
}
public static GFTranslator get() {
return instance;
}
}

View File

@@ -191,6 +191,11 @@ public class MainActivity extends Activity {
editor.commit();
return true;
case R.id.phrasebook: {
Intent myIntent = new Intent(MainActivity.this, se.chalmers.phrasebook.gui.activities.NavigationActivity.class);
MainActivity.this.startActivity(myIntent);
return true;
}
case R.id.topics: {
Intent myIntent = new Intent(MainActivity.this, AlternativesActivity.class);
MainActivity.this.startActivity(myIntent);

View File

@@ -0,0 +1,87 @@
package se.chalmers.phrasebook.backend;
import android.content.Context;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import org.grammaticalframework.pgf.Expr;
import org.grammaticalframework.ui.android.R;
import org.grammaticalframework.ui.android.GFTranslator;
import se.chalmers.phrasebook.backend.syntax.SyntaxNodeList;
import se.chalmers.phrasebook.backend.syntax.SyntaxTree;
/**
* Created by Björn on 2016-03-03.
*/
public class Model {
private static Model model;
private XMLParser parser;
private ArrayList<SyntaxTree> phrases;
private SyntaxTree currentPhrase;
private Model() {
try {
InputStream phrases = GFTranslator.get().getAssets().open("phrases.xml");
parser = new XMLParser(phrases);
phrases.close();
} catch (IOException e) {
e.printStackTrace();
}
phrases = new ArrayList<SyntaxTree>();
for (String s : parser.getSentencesData().keySet()) {
phrases.add(parser.getSyntaxTree(s));
}
}
public static Model getInstance() {
if (model == null) model = getSync();
return model;
}
private synchronized static Model getSync() {
if (model == null) model = new Model();
return model;
}
public void update(int optionIndex, SyntaxNodeList target, int childIndex, boolean isAdvanced) {
currentPhrase.setSelectedChild(optionIndex, target, childIndex, isAdvanced);
}
public ArrayList<String> getSentencesInCurrentPhrasebook() {
ArrayList<String> sentences = new ArrayList<String>();
for (int i = 0; i < phrases.size(); i++) {
sentences.add(parser.getSentencesData().get(phrases.get(i).getId()));
}
return sentences;
}
public void setCurrentPhrase(int position) {
SyntaxTree choosenPhrase = phrases.get(position);
currentPhrase = parser.getSyntaxTree(choosenPhrase.getId());
boolean status = currentPhrase.replicate(choosenPhrase);
}
public String getDescFromPos(int pos) {
return parser.getSentencesData()
.get((String) (parser.getSentencesData().keySet().toArray()[pos]));
}
public void setNumeralCurrentPhrase() {
for (int i = 0; i < parser.getSentencesData().values().size(); i++) {
if ((parser.getSentencesData().keySet().toArray()[i]).equals("NNumeral")) {
currentPhrase = parser.getSyntaxTree((String) parser.getSentencesData()
.keySet().toArray()[i]);
}
}
}
public SyntaxTree getCurrentPhrase() {
return currentPhrase;
}
}

View File

@@ -0,0 +1,196 @@
package se.chalmers.phrasebook.backend;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import se.chalmers.phrasebook.backend.syntax.NumeralSyntaxNode;
import se.chalmers.phrasebook.backend.syntax.SyntaxNode;
import se.chalmers.phrasebook.backend.syntax.SyntaxNodeList;
import se.chalmers.phrasebook.backend.syntax.SyntaxTree;
/**
* Created by David on 2016-02-19.
*/
public class XMLParser {
private DocumentBuilder documentBuilder;
private Document document;
private String currentId;
public XMLParser(InputStream is) {
try {
documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
document = documentBuilder.parse(is);
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public HashMap<String, String> getSentencesData() {
String[] result;
HashMap<String, String> sentenceMap = new HashMap<String, String>();
NodeList sentences = document.getElementsByTagName("sentence");
int nbrOfSentences = sentences.getLength();
for (int i = 0; i < nbrOfSentences; i++) {
String desc = sentences.item(i).getAttributes().getNamedItem("desc").getNodeValue();
String id = sentences.item(i).getAttributes().getNamedItem("id").getNodeValue();
if (desc != null && id != null)
sentenceMap.put(id, desc);
}
return sentenceMap;
}
public SyntaxTree getAdvancedOptionSyntaxTree() {
NodeList advSentence = document.getElementsByTagName("advanced");
advSentence = advSentence.item(0).getChildNodes();
SyntaxTree s = new SyntaxTree(constructSyntaxNodeList(advSentence, new SyntaxNode("Root"), new SyntaxNodeList(), null, 1));
return s;
}
public SyntaxTree getSyntaxTree(String sentenceTitle) {
NodeList result = null;
NodeList nl = document.getElementsByTagName("sentence");
boolean isAdvanced = false;
String id = "";
for (int i = 0; i < nl.getLength(); i++) {
NamedNodeMap attr = nl.item(i).getAttributes();
id = attr.getNamedItem("id").getNodeValue();
if (nl.item(i).getNodeType() == Node.ELEMENT_NODE && sentenceTitle.equals(id)) {
result = nl.item(i).getChildNodes();
if (attr.getNamedItem("advanced") != null) isAdvanced = true;
break;
}
}
SyntaxTree s = buildSyntaxTree(result);
s.setId(id);
if (isAdvanced) {
s.setAdvancedTree(getAdvancedOptionSyntaxTree());
}
return s;
}
private SyntaxTree buildSyntaxTree(NodeList currentRoot) {
SyntaxTree s = new SyntaxTree(constructSyntaxNodeList(currentRoot, new SyntaxNode("Root"), new SyntaxNodeList(), null, 1));
return s;
}
/*
"Abandon all hope, ye who enter here
*/
private SyntaxNode constructSyntaxNodeList(NodeList nl, SyntaxNode parent, SyntaxNodeList list, SyntaxNode nextSequence, int nbrOfArgs) {
if (nl == null || nl.getLength() < 1) {
if (nextSequence != null && !(parent.getData().isEmpty() && nextSequence.getSyntaxNodes().isEmpty())) {
list.add(nextSequence);
parent.getSyntaxNodes().add(list);
}
return null;
}
int length = nl.getLength();
//CurrentArgs counts the number of arguments for the current NodeList
int currentArgs = 0;
//If the parent node, or previous "recursion", calls for multiple args
if (nbrOfArgs > 1) {
currentArgs = nbrOfArgs;////Update currentArgs
nbrOfArgs = 0;//Reset nbrOfArgs, important due to the other recursive calls which will happen before nbrOfArgs is actually used.
}
int args = 0;
for (int i = 0; i < length; i++) {
if (nl.item(i) != null && (nl.item(i).getNodeType() == Node.ELEMENT_NODE) && nl.item(i).getAttributes() != null) {
String syntax = "", desc = "", option = "", question = "";
NamedNodeMap attributes = nl.item(i).getAttributes();
if (attributes.getNamedItem("syntax") != null) {
syntax = attributes.getNamedItem("syntax").getNodeValue();
}
if (attributes.getNamedItem("desc") != null) {
desc = attributes.getNamedItem("desc").getNodeValue();
}
if (attributes.getNamedItem("args") != null) {
args = Integer.parseInt(attributes.getNamedItem("args").getNodeValue());
nbrOfArgs = args;
}
if (attributes.getNamedItem("option") != null) {
question = attributes.getNamedItem("option").getNodeValue();
list.setQuestion(question);
constructSyntaxNodeList(nl.item(i).getChildNodes(), parent, list, nextSequence, nbrOfArgs);
}
if (attributes.getNamedItem("child") != null) {
option = attributes.getNamedItem("child").getNodeValue();
SyntaxNode mNextSequence = new SyntaxNode("");//This is a "holder" node to bind the child function calls nodes, contains no useful information in its syntax.
SyntaxNodeList mList = new SyntaxNodeList();
constructSyntaxNodeList(nl.item(i).getChildNodes(), mNextSequence, mList, nextSequence, nbrOfArgs);
constructSyntaxNodeList(jumpToChild("child", option), parent, list, mNextSequence, nbrOfArgs);
}
if (!syntax.isEmpty()) {
SyntaxNode node;
if (syntax.equals("NNumeral")) {
node = new NumeralSyntaxNode();
} else {
node = new SyntaxNode(syntax);
node.setDesc(desc);
}
list.add(node);
SyntaxNodeList mList = new SyntaxNodeList();
constructSyntaxNodeList(nl.item(i).getChildNodes(), node, mList, nextSequence, nbrOfArgs);
}
//Add the list to the current parent node list
if (!list.getChildren().isEmpty() && !parent.getSyntaxNodes().contains(list)) {
parent.getSyntaxNodes().add(list);
}
//Check if current node is multiple arg nodes i.e. add another list to its syntaxNodes.
if (currentArgs > 1 && parent.getSyntaxNodes().size() < currentArgs) {
list = new SyntaxNodeList();
}
}
}
return parent;
}
public NodeList jumpToChild(String tag, String id) {
NodeList result = null;
NodeList nl = document.getElementsByTagName(tag);
for (int i = 0; i < nl.getLength(); i++) {
String s = nl.item(i).getFirstChild().getNodeValue();
if (nl.item(i).getNodeType() == Node.ELEMENT_NODE && nl.item(i).getAttributes().getNamedItem("id").getNodeValue().equals(id)) {
result = nl.item(i).getChildNodes();
}
}
return result;
}
}

View File

@@ -0,0 +1,104 @@
package se.chalmers.phrasebook.backend.syntax;
/**
* Created by Björn on 2016-04-04.
*/
public class NumeralSyntaxNode extends SyntaxNode {
private int number = 1;
public NumeralSyntaxNode() {
super("NNumeral");
}
@Override
public boolean isModular() {
return true;
}
public String getData() {
try {
return nbrToSyntax(number);
}catch(IllegalArgumentException e) {
//Returns the syntax for "1" in case of erroneous input.
return "(NNumeral(num (pot2as3 (pot1as2 (pot0as1 pot01)))))";
}
}
public String getDesc() {
return Integer.toString(number);
}
public void setDesc(String number) {
this.number = Integer.parseInt(number);
}
@Override
public void setSelectedChild(int listIndex, SyntaxNode newChild) {
setDesc(Integer.toString(listIndex));
}
private String nbrToSyntax(int nbr) throws IllegalArgumentException {
String syntax = "";
if(nbr < 1000000 && nbr > 0) {
if (nbr <=999) {
syntax = "(NNumeral(num(pot2as3 " + subs1000(nbr) + ")))";
} else if(nbr % 1000 == 0) {
syntax = "(NNumeral(num(pot3 " + subs1000(nbr/1000) + ")))";
} else if(nbr > 1000 && nbr%1000 != 0) {
syntax = "(NNumeral(num(pot3plus " + subs1000(nbr/1000) + " " +
subs1000(nbr%1000) + ")))";
}
} else {
throw new IllegalArgumentException("Input must be between 1 and 999999");
}
return syntax;
}
private String subs1000(int nbr) {
String syntax = "";
if(nbr < 100) {
syntax = "(pot1as2 " + subs100(nbr) + ")";
} else if(nbr % 100 == 0) {
syntax = "(pot2 " + subs10(nbr/100) + ")";
} else if(nbr > 100 && nbr%100 != 0) {
syntax = "(pot2plus " + subs10(nbr/100) + " " + subs100(nbr%100) + ")";
}
return syntax;
}
private String subs100(int nbr) {
String syntax = "";
if(nbr < 10) {
syntax = "(pot0as1 " + subs10(nbr) + ")";
} else if(nbr == 10 || nbr == 11) {
syntax = "pot1" + nbr;
} else if(nbr >= 12 && nbr <= 19) {
syntax = "(pot1to19 n" + nbr%10 + ")";
} else if(nbr >= 20 && nbr%10 == 0) {
syntax = "(pot1 n" + Integer.toString(nbr/10) + ")";
} else if(nbr%10 != 0) {
syntax = "(pot1plus n" + nbr/10 + " " + subs10(nbr%10) + ")";
}
return syntax;
}
private String subs10(int nbr) {
String syntax = "";
if (nbr == 1) {
syntax = "pot01";
} else if (nbr >= 2 && nbr <= 9) {
syntax = "(pot0 n" + nbr + ")";
}
return syntax;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
}

View File

@@ -0,0 +1,66 @@
package se.chalmers.phrasebook.backend.syntax;
import java.io.Serializable;
import java.util.ArrayList;
/**
* Created by Björn on 2016-03-03.
*/
public class SyntaxNode implements Serializable {
private String data;
private String desc;
private ArrayList<SyntaxNodeList> syntaxNodes;
public SyntaxNode(String data) {
syntaxNodes = new ArrayList<SyntaxNodeList>();
this.data = data;
}
public void setSelectedChild(int listIndex, SyntaxNode newChild) {
syntaxNodes.get(listIndex).setSelectedChild(newChild);
}
public ArrayList<SyntaxNodeList> getSyntaxNodes() {
return syntaxNodes;
}
public ArrayList<SyntaxNodeList> getModularSyntaxNodes() {
ArrayList<SyntaxNodeList> result = new ArrayList<SyntaxNodeList>();
for (SyntaxNodeList snl : syntaxNodes) {
if (snl.getChildren().size() > 1) result.add(snl);
}
return result;
}
public String getData() {
return data;
}
public boolean isModular() {
for (SyntaxNodeList s : syntaxNodes) if (s.getChildren().size() > 1) return true;
return false;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof SyntaxNode)) {
return false;
}
SyntaxNode n = (SyntaxNode) o;
return this.data.equals(n.data);
}
}

View File

@@ -0,0 +1,62 @@
package se.chalmers.phrasebook.backend.syntax;
import java.io.Serializable;
import java.util.ArrayList;
import se.chalmers.phrasebook.backend.syntax.SyntaxNode;
/**
* Created by David on 2016-04-01.
*/
public class SyntaxNodeList implements Serializable {
private SyntaxNode selectedChild;
private ArrayList<SyntaxNode> children;
private String question;
public SyntaxNodeList() {
children = new ArrayList<SyntaxNode>();
}
public ArrayList<SyntaxNode> getChildren() {
return children;
}
public boolean add(SyntaxNode object) {
if (selectedChild == null)
selectedChild = object;
return children.add(object);
}
public SyntaxNode getSelectedChild() {
return selectedChild;
}
public boolean setSelectedChild(SyntaxNode selectedChild) {
if(children.contains(selectedChild)) {
this.selectedChild = selectedChild;
return true;
}
return false;
}
public boolean selectChild(String description) {
for (SyntaxNode s : children) {
if (s.getDesc().equals(description)) {
setSelectedChild(s);
return true;
}
}
return false;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
}

View File

@@ -0,0 +1,224 @@
package se.chalmers.phrasebook.backend.syntax;
import java.io.Serializable;
import java.util.ArrayList;
import org.grammaticalframework.pgf.Expr;
/**
* Created by Björn on 2016-02-26.
*/
public class SyntaxTree implements Serializable {
private String id;
private SyntaxNode root;
private boolean advActivated;
private boolean favorite;
private ArrayList<SyntaxNodeList> options = new ArrayList<SyntaxNodeList>();
private SyntaxTree advancedTree; //Realy ugly solution but the only one we can think of as
public SyntaxTree getAdvancedTree() {
return advancedTree;
}
public void setAdvancedTree(SyntaxTree advancedTree) {
this.advancedTree = advancedTree;
}
public SyntaxTree(SyntaxNode root) {
this.root = root;
advActivated = false;
initializeOptions(this.root);
}
public ArrayList<SyntaxNodeList> getOptions() {
return options;
}
public ArrayList<SyntaxNodeList> getAdvOptions() {
if(advancedTree != null) {
return advancedTree.getOptions();
}
return new ArrayList<SyntaxNodeList>();
}
public boolean getFavorite() {
return favorite;
}
public void setFavorite(boolean fav) {
favorite = fav;
}
public boolean replicate(SyntaxTree tree) {
if(this.getOptions() == null) {
return false;
} else {
for(int i = 0; i < getOptions().size(); i++) {
for(SyntaxNode n: getOptions().get(i).getChildren()) {
if(n.getData().equals(tree.getOptions().get(i).getSelectedChild().getData())) {
this.setSelectedChild(getOptions().get(i), n);
} else if(n instanceof NumeralSyntaxNode) {
((NumeralSyntaxNode) n).setDesc
(Integer.toString(((NumeralSyntaxNode)tree.getOptions()
.get(i).getSelectedChild()).getNumber()));
}
}
}
}
tree.setFavorite(getFavorite());
if(advancedTree != null) {
if(tree.advActivated) {
setAdvActivated(true);
return advancedTree.replicate(tree.getAdvancedTree());
}
}
return false;
}
public void setId(String id) {
this.id = id;
}
//creates an ArrayList of LinkedHashMaps, each representing
//a currently available option to be customized.
private void initializeOptions(SyntaxNode currentRoot) {
if (currentRoot == null) return;
if (currentRoot.isModular()) {
for (SyntaxNodeList l : currentRoot.getSyntaxNodes()) {
if (l.getQuestion() != null && !options.contains(l)) {
options.add(l);
}
initializeOptions(l.getSelectedChild());
}
} else if (currentRoot.getSyntaxNodes() != null && currentRoot.getSyntaxNodes().size() > 0) {
for (SyntaxNodeList n : currentRoot.getSyntaxNodes()) {
initializeOptions(n.getSelectedChild());
}
}
}
public String getId() {
return id;
}
public boolean setSelectedChild(int optionIndex, int childIndex, boolean isAdvanced) {
boolean status = false;
if(!isAdvanced) {
if (options.get(optionIndex).getSelectedChild() instanceof NumeralSyntaxNode) {
options.get(optionIndex).getSelectedChild().setSelectedChild(childIndex, null);
status = true;
} else if (options.get(optionIndex) != null) {
if (options.get(optionIndex).getChildren().get(childIndex) != null)
status = options.get(optionIndex).setSelectedChild(options.get(optionIndex).getChildren().get(childIndex));
}
} else {
advancedTree.setSelectedChild(optionIndex,childIndex,false);
}
return status;
}
public void setSelectedChild(int optionIndex, SyntaxNodeList snl, int childIndex, boolean isAdvanced) {
if(!isAdvanced) {
if (snl != null) {
SyntaxNodeList nodeList = options.get(optionIndex);
setRecursiveSelectedChild(nodeList, snl, childIndex);
} else {
setSelectedChild(optionIndex, childIndex,false);
}
} else {
advancedTree.setSelectedChild(optionIndex,snl,childIndex,false);
}
}
private void setRecursiveSelectedChild(SyntaxNodeList nodeList, SyntaxNodeList optionTarget, int childIndex) {
if (nodeList.equals(optionTarget)) {
setSelectedChild(nodeList, nodeList.getChildren().get(childIndex));
} else {
for (SyntaxNodeList list : nodeList.getSelectedChild().getSyntaxNodes())
setRecursiveSelectedChild(list, optionTarget, childIndex);
}
}
public boolean setSelectedChild(SyntaxNodeList l, SyntaxNode s) {
return l.setSelectedChild(s);
}
/**
* Parses the selected children into a text syntax usable by the grammar to
* generate a translation. Builds recursivly.
*
* @return The syntax usable by the GF-grammar to generate a translation
*/
public String getSyntax() {
return parseSentenceSyntax(getSentenceHead());
}
//TODO A really ugly hack, should DEFINITIVELY BE FIXED
public Expr getAdvSyntax() {
String syntax = getSyntax();
if(advActivated) {
String advSyntax = advancedTree.getSyntax();
if(!advSyntax.isEmpty()) {
String test = advSyntax.substring(0, advSyntax.indexOf("AKnow") + 5) +
syntax.substring(1, 9) + "(" +
advSyntax.substring(advSyntax.indexOf("AKnow") + 6, advSyntax.length() - 3) +
syntax.substring(9, syntax.length()) + ")))";
return Expr.readExpr(test);
}
}
return Expr.readExpr(syntax);
}
public boolean hasAdvOptions() {
return (advancedTree != null);
}
// Builds recursively from root node to parse syntax
//the getSyntax() method acts as a wrapper
private String parseSentenceSyntax(SyntaxNode node) {
if (node.getSyntaxNodes().size() < 1) {
return node.getData();
} else {
String syntax = node.getData();
for (int i = 0; i < node.getSyntaxNodes().size(); i++) {
if (node.getSyntaxNodes().get(i).getSelectedChild().getData().isEmpty()) {
syntax += parseSentenceSyntax(node.getSyntaxNodes().get(i).getSelectedChild());
} else {
syntax = syntax + "(" + parseSentenceSyntax(node.getSyntaxNodes().get(i).getSelectedChild()) + ")";
if (node.getSyntaxNodes().size() > 1) {
syntax += " ";
}
}
}
return syntax;
}
}
private SyntaxNode getSentenceHead() {
if (root.getSyntaxNodes().get(0) != null)
return root.getSyntaxNodes().get(0).getSelectedChild();//TODO Might cause bugs
return null;
}
public boolean isAdvActivated(){
return advActivated;
}
public void setAdvActivated(boolean activated){
advActivated = activated;
}
}

View File

@@ -0,0 +1,17 @@
package se.chalmers.phrasebook.gui;
import se.chalmers.phrasebook.backend.syntax.SyntaxNodeList;
/**
* An interface for communication between a fragment to an activity
* Created by David on 2016-04-13.
*/
public interface FragmentCommunicator {
void updateSyntax(int optionIndex, SyntaxNodeList l, int childIndex, boolean isAdvanced);
void pageChanged();
void setToTranslationFragment(int id);
void updateTranslation();
}

View File

@@ -0,0 +1,100 @@
package se.chalmers.phrasebook.gui.activities;
import android.app.ActionBar;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.widget.DrawerLayout;
import org.grammaticalframework.ui.android.R;
import se.chalmers.phrasebook.backend.Model;
import se.chalmers.phrasebook.backend.syntax.SyntaxNodeList;
import se.chalmers.phrasebook.gui.FragmentCommunicator;
import se.chalmers.phrasebook.gui.fragments.NumeralTranslatorFragment;
import se.chalmers.phrasebook.gui.fragments.PhraseListFragment;
import se.chalmers.phrasebook.gui.fragments.TranslatorFragment;
public class NavigationActivity extends FragmentActivity implements FragmentCommunicator {
/**
* Used to store the last screen title. For use in {@link #restoreActionBar()}.
*/
private CharSequence mTitle;
private Fragment mContent;
public void pageChanged() {
if (mContent instanceof TranslatorFragment)
((TranslatorFragment) mContent).displayDots();
}
private Model mModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation);
mModel = Model.getInstance();
mTitle = getTitle();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.container, PhraseListFragment.newInstance("Phrasebook"));
transaction.commit();
}
public void switchContent(Fragment fragment, String message) {
mContent = fragment;
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.container, fragment);
transaction.addToBackStack(message);
transaction.commit();
}
public void restoreActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
@Override
public void onBackPressed() {
if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
getSupportFragmentManager().popBackStack();
getSupportFragmentManager().beginTransaction().commit();
//Switches to the previous entry on the stack to ensure
//that mContent is preserved
mContent = getSupportFragmentManager().getFragments()
.get(getSupportFragmentManager().getFragments().size() - 2);
} else {
super.onBackPressed();
}
}
@Override
public void updateSyntax(int optionIndex, SyntaxNodeList l, int childIndex, boolean isAdvanced) {
mModel.update(optionIndex, l, childIndex, isAdvanced);
updateTranslation();
}
public void updateTranslation() {
if (mContent instanceof TranslatorFragment) {
TranslatorFragment fragment = (TranslatorFragment) mContent;
fragment.updateTranslation();
}
}
@Override
public void setToTranslationFragment(int id) {
switchContent(TranslatorFragment.newInstance(id + ""), "");
}
}

View File

@@ -0,0 +1,59 @@
package se.chalmers.phrasebook.gui.adapters;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;
import se.chalmers.phrasebook.backend.Model;
import se.chalmers.phrasebook.gui.FragmentCommunicator;
import se.chalmers.phrasebook.gui.smallFragments.OptionsFragment;
/**
* Created by matilda on 15/03/16.
*/
public class SwipeAdapter extends FragmentPagerAdapter {
private int pages;
private FragmentCommunicator mCallback;
private Model model;
public SwipeAdapter(FragmentManager fragmentManager, FragmentCommunicator mCallback) {
super(fragmentManager);
this.mCallback = mCallback;
model = Model.getInstance();
if(model.getCurrentPhrase().hasAdvOptions()) {
pages = 2;
} else {
pages = 1;
}
}
// Returns total number of pages
@Override
public int getCount() {
return pages;
}
@Override
public void startUpdate(ViewGroup container) {
mCallback.pageChanged();
}
// Returns the fragment to display for that page
@Override
public Fragment getItem(int position) {
switch(position){
case 0:
return OptionsFragment.newInstance(1, false);
case 1:
return OptionsFragment.newInstance(2, model.getCurrentPhrase().isAdvActivated());
default:
return null;
}
}
}

View File

@@ -0,0 +1,36 @@
package se.chalmers.phrasebook.gui.fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import se.chalmers.phrasebook.backend.Model;
/**
* Created by Björn on 2016-04-25.
*/
public class NumeralTranslatorFragment extends TranslatorFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
model = Model.getInstance();
}
public static NumeralTranslatorFragment newInstance() {
NumeralTranslatorFragment fragment = new NumeralTranslatorFragment();
Bundle args = new Bundle();
args.putString("phrase", "NNumeral");
fragment.setArguments(args);
return fragment;
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceStat) {
View view = super.onCreateView(inflater, container,
savedInstanceStat);
super.model.setNumeralCurrentPhrase();
return view;
}
}

View File

@@ -0,0 +1,111 @@
package se.chalmers.phrasebook.gui.fragments;
import android.os.Bundle;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.LocalBroadcastManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import org.grammaticalframework.ui.android.R;
import se.chalmers.phrasebook.backend.Model;
import se.chalmers.phrasebook.backend.syntax.SyntaxTree;
import se.chalmers.phrasebook.gui.FragmentCommunicator;
import se.chalmers.phrasebook.gui.activities.NavigationActivity;
/**
* Created by Björn on 2016-04-25.
*/
public class PhraseListFragment extends Fragment {
protected Model model;
protected ArrayList<String> phrases;
Context context;
private String title;
private FragmentCommunicator mCallback;
public static PhraseListFragment newInstance(String title) {
PhraseListFragment fragment = new PhraseListFragment();
Bundle args = new Bundle();
args.putString("title", title);
fragment.setArguments(args);
return fragment;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception
try {
mCallback = (FragmentCommunicator) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnHeadlineSelectedListener");
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
model = Model.getInstance();
context = getActivity().getApplicationContext();
title = getArguments().getString("title");
phrases = new ArrayList<String>();
phrases.addAll(model.getSentencesInCurrentPhrasebook());
}
@Override
public void onResume() {
super.onResume();
phrases.clear();
phrases.addAll(model.getSentencesInCurrentPhrasebook());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_phrase_list, container, false);
getActivity().getActionBar().setTitle(title);
ArrayAdapter adapter = new ArrayAdapter<String>(context, R.layout.phrase_list_item, phrases);
final ListView phraseListView = (ListView) view.findViewById(R.id.phrase_listView);
phraseListView.setAdapter(adapter);
phraseListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
model.setCurrentPhrase(position);
((NavigationActivity)mCallback).getActionBar().setTitle(model.getDescFromPos(position));
sendMessage(position);
}
});
return view;
}
private void sendMessage(int position) {
mCallback.setToTranslationFragment(position);
}
}

View File

@@ -0,0 +1,81 @@
package se.chalmers.phrasebook.gui.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import org.grammaticalframework.ui.android.GFTranslator;
import org.grammaticalframework.ui.android.R;
import se.chalmers.phrasebook.backend.Model;
import se.chalmers.phrasebook.gui.smallFragments.SwipeFragment;
import se.chalmers.phrasebook.gui.smallFragments.TranslationFragment;
/**
* Created by matilda on 04/04/16.
*/
public class TranslatorFragment extends Fragment {
protected Model model;
private SwipeFragment swiper;
private View view;
public static TranslatorFragment newInstance(String phrase) {
TranslatorFragment fragment = new TranslatorFragment();
Bundle args = new Bundle();
args.putString("phrase", phrase);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
model = Model.getInstance();
}
public void displayDots() {
if(swiper.isAdvanced(view.findViewById(R.id.containerfor_options))) {
((ImageView)view.findViewById(R.id.firstDot))
.setImageResource(R.drawable.ic_dictionary);
((ImageView)view.findViewById(R.id.secondDot))
.setImageResource(R.drawable.ic_dictionary);
} else {
((ImageView)view.findViewById(R.id.secondDot))
.setImageResource(R.drawable.ic_dictionary);
((ImageView)view.findViewById(R.id.firstDot))
.setImageResource(R.drawable.ic_dictionary);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_translator, container, false);
final FragmentTransaction fm = getChildFragmentManager().beginTransaction();
swiper = new SwipeFragment();
fm.replace(R.id.containerfor_translation, new TranslationFragment());
fm.replace(R.id.containerfor_options, new SwipeFragment());
fm.commit();
if(!model.getCurrentPhrase().hasAdvOptions()) {
view.findViewById(R.id.firstDot).setVisibility(View.GONE);
view.findViewById(R.id.secondDot).setVisibility(View.GONE);
}
return view;
}
public void updateTranslation() {
TranslationFragment translationFragment = (TranslationFragment) getChildFragmentManager().findFragmentById(R.id.containerfor_translation);
if (translationFragment != null)
translationFragment.updateData();
}
}

View File

@@ -0,0 +1,91 @@
package se.chalmers.phrasebook.gui.smallFragments;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import org.grammaticalframework.ui.android.R;
import se.chalmers.phrasebook.backend.Model;
import se.chalmers.phrasebook.gui.FragmentCommunicator;
import se.chalmers.phrasebook.gui.fragments.TranslatorFragment;
/**
* Created by matilda on 02/05/16.
*/
public class AdvancedOptionsButtonFragment extends Fragment{
private boolean active;
private Model model;
private FragmentCommunicator mCallback;
public static Fragment newInstance(boolean active) {
AdvancedOptionsButtonFragment advancedOptionsButtonFragment = new AdvancedOptionsButtonFragment();
Bundle args = new Bundle();
args.putBoolean("active", active);
advancedOptionsButtonFragment.setArguments(args);
return advancedOptionsButtonFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
model = Model.getInstance();
this.active = getArguments().getBoolean("active");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.advanced_options_button, container, false);
CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkBox);
checkBox.setText("Use reported speech ('I Know that...')");
if(active != true){
checkBox.setChecked(false);
} else {
checkBox.setChecked(true);
}
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
model.getCurrentPhrase().setAdvActivated(true);
((OptionsFragment)getParentFragment()).update(true);
} else {
model.getCurrentPhrase().setAdvActivated(false);
((OptionsFragment)getParentFragment()).update(false);
}
mCallback.updateTranslation();
}
});
return view;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception
try {
mCallback = (FragmentCommunicator) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnHeadlineSelectedListener");
}
}
}

View File

@@ -0,0 +1,167 @@
package se.chalmers.phrasebook.gui.smallFragments;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.ArrayList;
import org.grammaticalframework.ui.android.R;
import se.chalmers.phrasebook.backend.Model;
import se.chalmers.phrasebook.backend.syntax.NumeralSyntaxNode;
import se.chalmers.phrasebook.backend.syntax.SyntaxNodeList;
import se.chalmers.phrasebook.gui.FragmentCommunicator;
/**
* Created by David on 2016-04-13.
*/
public class InputHolderFragment extends Fragment {
private Model model;
private int optionIndex;
private SyntaxNodeList guiOptions;
private FragmentManager fragmentManager;
private ArrayList<String> fragmentTags;
private boolean isAdvanced;
private FragmentCommunicator mCallback;
public static Fragment newInstance(int optionIndex, boolean isAdvanced) {
InputHolderFragment inputHolderFragment = new InputHolderFragment();
Bundle args = new Bundle();
args.putInt("index", optionIndex);
args.putBoolean("advanced", isAdvanced);
inputHolderFragment.setArguments(args);
return inputHolderFragment;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception
try {
mCallback = (FragmentCommunicator) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnHeadlineSelectedListener");
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.isAdvanced = getArguments().getBoolean("advanced");
model = Model.getInstance();
optionIndex = getArguments().getInt("index");
fragmentManager = getChildFragmentManager();
if (isAdvanced) {
guiOptions = model.getCurrentPhrase().getAdvOptions().get(optionIndex);
} else {
guiOptions = model.getCurrentPhrase().getOptions().get(optionIndex);
}
fragmentTags = new ArrayList<String>();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.small_fragment_input_holder, container, false);
TextView textView = (TextView) view.findViewById(R.id.holderOptionText);
textView.setText(guiOptions.getQuestion());
addInputFragments(guiOptions);
return view;
}
private void addListInputFragment(SyntaxNodeList l) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
String s = "Input: " + l.toString();
transaction.add(R.id.input_holder, SpinnerInputFragment.newInstance(optionIndex, null, l), s);
fragmentTags.add(s);
transaction.commit();
}
private void addNumberInputFragment(SyntaxNodeList l) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
String s = "Input: " + l.toString();
int defaultIntValue = 0;
// String title = l.getQuestion();
String title = "";
NumeralSyntaxNode nsn = (NumeralSyntaxNode) l.getSelectedChild();
defaultIntValue = nsn.getNumber();
transaction.replace(R.id.input_holder, NumberInputFragment.newInstance(optionIndex, title, defaultIntValue), s);
fragmentTags.add(s);
transaction.commit();
}
private void redrawInputGUI() {
clearInputs();
addInputFragments(guiOptions);
}
private void addInputFragments(SyntaxNodeList snl) {
if (snl != null) {
if (snl.getSelectedChild() instanceof NumeralSyntaxNode) {
addNumberInputFragment(snl);
} else {
addListInputFragment(snl);
}
if (snl.getSelectedChild().isModular()) {
ArrayList<SyntaxNodeList> modularLists = snl.getSelectedChild().getModularSyntaxNodes();
for (SyntaxNodeList nodeList : modularLists)
addInputFragments(nodeList);
}
}
}
private void clearInputs() {
FragmentTransaction transaction = fragmentManager.beginTransaction();
for (String tag : fragmentTags) {
Fragment fragment = fragmentManager.findFragmentByTag(tag);
transaction.remove(fragment);
}
fragmentTags.clear();
transaction.commit();
}
public void updateSyntax(int optionIndex, SyntaxNodeList l, int childIndex) {
if (this.optionIndex == optionIndex) {
mCallback.updateSyntax(optionIndex, l, childIndex, isAdvanced);
this.redrawInputGUI();
}
}
public void updateNumeralSyntax(int optionIndex, int childIndex) {
if (this.optionIndex == optionIndex) {
mCallback.updateSyntax(optionIndex, null, childIndex, false);
}
this.redrawInputGUI();
}
}

View File

@@ -0,0 +1,147 @@
package se.chalmers.phrasebook.gui.smallFragments;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.PasswordTransformationMethod;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;
import org.grammaticalframework.ui.android.R;
import se.chalmers.phrasebook.backend.Model;
import se.chalmers.phrasebook.backend.syntax.SyntaxNode;
import se.chalmers.phrasebook.backend.syntax.SyntaxNodeList;
/**
* Created by David on 2016-04-07.
*/
public class NumberInputFragment extends Fragment {
private Model model;
private int spinnerIndex;
private SyntaxNodeList options;
private int optionIndex;
private String label;
private int defaultInt;
private EditText editNumber;
private int currentNumber;
public static NumberInputFragment newInstance(int optionIndex, String title, int defaultInt) {
NumberInputFragment numberInputFragment = new NumberInputFragment();
Bundle args = new Bundle();
args.putInt("optionIndex", optionIndex);
args.putString("title", title);
args.putInt("defaultInt", defaultInt);
numberInputFragment.setArguments(args);
return numberInputFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
model = Model.getInstance();
optionIndex = getArguments().getInt("optionIndex");
label = getArguments().getString("title");
defaultInt = getArguments().getInt("defaultInt");
}
private class NumericKeyBoardTransformationMethod extends PasswordTransformationMethod {
@Override
public CharSequence getTransformation(CharSequence source, View view) {
return source;
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.small_fragment_number, container, false);
TextView viewLabel = (TextView) view.findViewById(R.id.textView_number);
final SeekBar seekBar = (SeekBar) view.findViewById(R.id.seekBar);
editNumber = (EditText) view.findViewById(R.id.editNumber);
viewLabel.setText(label);
seekBar.setProgress(defaultInt);
editNumber.setText(""+defaultInt);
editNumber.setTransformationMethod(new NumericKeyBoardTransformationMethod());
editNumber.requestFocus();
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
currentNumber = progress;
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
editNumber.setText(""+currentNumber);
sendMessage(optionIndex, currentNumber);
}
});
editNumber.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if(editNumber.getText().toString().equals("")) {
currentNumber = 0;
} else if(editNumber.getText().toString().length() < 7){
currentNumber = Integer.parseInt(editNumber.getText().toString());
editNumber.setInputType(0);
sendMessage(optionIndex, currentNumber);
} else {
editNumber.setText(""+editNumber.getText().toString()
.substring(0,editNumber.getText().toString().length()-1));
}
seekBar.setProgress(currentNumber);
}
});
return view;
}
private void sendMessage(int optionIndex, int childIndex) {
InputHolderFragment fragment = (InputHolderFragment) getParentFragment();
//options är ju tom i det här fragmentet, hur ska vi lösa det?
fragment.updateSyntax(optionIndex, options,childIndex);
}
}

View File

@@ -0,0 +1,107 @@
package se.chalmers.phrasebook.gui.smallFragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import org.grammaticalframework.ui.android.R;
import se.chalmers.phrasebook.backend.Model;
import se.chalmers.phrasebook.backend.syntax.SyntaxNodeList;
public class OptionsFragment extends Fragment {
private Model model;
private ArrayList<SyntaxNodeList> options;
private ArrayList<SyntaxNodeList> advancedOptions;
private int type;
private boolean advActive;
private int[] containers;
public static OptionsFragment newInstance(int type, boolean advActive) {
OptionsFragment optionsFragment = new OptionsFragment();
Bundle args = new Bundle();
args.putInt("index", type);
args.putBoolean("advActive", advActive);
optionsFragment.setArguments(args);
return optionsFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
model = Model.getInstance();
type = getArguments().getInt("index");
advActive = getArguments().getBoolean("advActive");
options = model.getCurrentPhrase().getOptions();
advancedOptions = model.getCurrentPhrase().getAdvOptions();
containers = new int[6];
addContainers();
addFragments();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.small_fragment_options, container, false);
}
private void addFragments() {
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
if (type == 1) {
for (int i = 0; i < options.size(); i++) {
if (options.get(i) != null) {
transaction.replace(containers[i], (InputHolderFragment.newInstance(i, false)));
}
}
} else if (type == 2) {
transaction.replace(containers[0], AdvancedOptionsButtonFragment.newInstance(advActive));
if (advActive) {
for (int i = 0; i < advancedOptions.size(); i++) {
if (advancedOptions.get(i) != null)
transaction.replace(containers[i + 1], InputHolderFragment.newInstance(i, true));
}
} else {
//Replaces with empty fragments
for (int i = 0; i < advancedOptions.size(); i++) {
if (advancedOptions.get(i) != null)
transaction.replace(containers[i + 1], new Fragment());
}
}
}
transaction.commit();
}
public void update(boolean advActive) {
this.advActive = advActive;
addFragments();
}
private void addContainers() {
containers[0] = R.id.child_fragment1;
containers[1] = R.id.child_fragment2;
containers[2] = R.id.child_fragment3;
containers[3] = R.id.child_fragment4;
containers[4] = R.id.child_fragment5;
containers[5] = R.id.child_fragment6;
}
}

View File

@@ -0,0 +1,124 @@
package se.chalmers.phrasebook.gui.smallFragments;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import org.grammaticalframework.ui.android.R;
import se.chalmers.phrasebook.backend.Model;
import se.chalmers.phrasebook.backend.syntax.SyntaxNode;
import se.chalmers.phrasebook.backend.syntax.SyntaxNodeList;
import se.chalmers.phrasebook.gui.FragmentCommunicator;
/**
* Created by matilda on 14/03/16.
*/
public class SpinnerInputFragment extends Fragment {
private Model model;
private int spinnerIndex;
private SyntaxNodeList options;
private String label;
private String currentChoice;
private Spinner spinner;
public static SpinnerInputFragment newInstance(int optionIndex, String title, SyntaxNodeList options) {
SpinnerInputFragment spinnerInputFragment = new SpinnerInputFragment();
Bundle args = new Bundle();
args.putInt("index", optionIndex);
args.putString("title", title);
args.putSerializable("spinner_options", options);
spinnerInputFragment.setArguments(args);
return spinnerInputFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
model = Model.getInstance();
label = getArguments().getString("title");
spinnerIndex = getArguments().getInt("index");
options = (SyntaxNodeList) getArguments().getSerializable("spinner_options");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.small_fragment_spinner, container, false);
TextView viewLabel = (TextView) view.findViewById(R.id.text_view_spinner);
spinner = (Spinner) view.findViewById(R.id.choice_spinner);
if (label == null) {
viewLabel.setVisibility(View.GONE);
} else {
viewLabel.setText(label);
}
String[] children = new String[options.getChildren().size()];
int i = 0;
int selectedIndex = 0;
for (SyntaxNode s : options.getChildren()) {
if(s == options.getSelectedChild())
selectedIndex = i;
children[i] = s.getDesc();
i++;
}
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,children);
adapter.setDropDownViewResource(android.R.layout.simple_list_item_1);
spinner.setAdapter(adapter);
spinner.setSelection(selectedIndex);
currentChoice = spinner.getSelectedItem().toString();
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (!spinner.getSelectedItem().toString().equals(currentChoice)) {
sendMessage(spinnerIndex, spinner.getSelectedItemPosition());
currentChoice = spinner.getSelectedItem().toString();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
return view;
}
private void sendMessage(int optionIndex, int childIndex) {
InputHolderFragment fragment = (InputHolderFragment) getParentFragment();
fragment.updateSyntax(optionIndex, options,childIndex);
// Intent intent = new Intent();
// intent.setAction("gui_update");
// intent.putExtra("optionIndex", optionIndex);
// intent.putExtra("childIndex", childIndex);
//
// LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).sendBroadcast(intent);
}
}

View File

@@ -0,0 +1,59 @@
package se.chalmers.phrasebook.gui.smallFragments;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.grammaticalframework.ui.android.R;
import se.chalmers.phrasebook.gui.FragmentCommunicator;
import se.chalmers.phrasebook.gui.adapters.SwipeAdapter;
public class SwipeFragment extends Fragment {
private ViewPager pager;
private SwipeAdapter swipeAdapter;
private FragmentCommunicator mCallback;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.small_fragment_swipe, container, false);
pager = (ViewPager)view.findViewById(R.id.vpPager);
swipeAdapter = new SwipeAdapter(getChildFragmentManager(), mCallback);
pager.setAdapter(swipeAdapter);
return view;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
System.out.println("Attaching");
// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception
try {
mCallback = (FragmentCommunicator) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnHeadlineSelectedListener");
}
}
public boolean isAdvanced(View view) {
pager = (ViewPager)view.findViewById(R.id.vpPager);
try {
return ((ViewPager)view.findViewById(R.id.vpPager)).getCurrentItem() == 1;
}catch(NullPointerException e) {
return false;
}
}
}

View File

@@ -0,0 +1,83 @@
package se.chalmers.phrasebook.gui.smallFragments;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.ImageView;
import org.grammaticalframework.pgf.Expr;
import org.grammaticalframework.ui.android.Translator;
import org.grammaticalframework.ui.android.GFTranslator;
import org.grammaticalframework.ui.android.TTS;
import org.grammaticalframework.ui.android.R;
import se.chalmers.phrasebook.backend.Model;
/**
* Created by matilda on 10/03/16.
*/
public class TranslationFragment extends Fragment {
private View translateView;
private Model mModel;
private TextView origin,target;
Translator mTranslator;
private TTS mTts;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mModel = Model.getInstance();
mTranslator = ((GFTranslator) getContext().getApplicationContext()).getTranslator();
mTts = new TTS(getActivity());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
translateView = inflater.inflate(R.layout.small_fragment_translation, container, false);
origin = (TextView) translateView.findViewById(R.id.origin_phrase);
target = (TextView) translateView.findViewById(R.id.target_phrase);
ImageView button = (ImageView) translateView.findViewById(R.id.button3);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mTts.speak(mTranslator.getTargetLanguage().getLangCode(), getTargetTranslation());
}
});
return translateView;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
updateData();
}
@Override
public void onDestroy() {
if (mTts != null) {
mTts.destroy();
mTts = null;
}
super.onDestroy();
}
public String getTargetTranslation() {
return target.getText().toString();
}
public void updateData() {
Expr expr = mModel.getCurrentPhrase().getAdvSyntax();
origin.setText(mTranslator.linearizeSource(expr));
target.setText(mTranslator.linearize(expr));
}
}