BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
diff --git a/src/ui/android/README b/src/ui/android/README
deleted file mode 100644
index 7adb7fe50..000000000
--- a/src/ui/android/README
+++ /dev/null
@@ -1,68 +0,0 @@
-= Overview =
-
-This directory contains a sample Android app tht uses
-the Android speech recognition and TTS APIs along with
-JNI bindings to the C PGF runtime to implement a simple
-speech translation app.
-
-
-= Requirements =
-
-1. Android SDK: http://developer.android.com/sdk/
- installed in $ANDROID_SDK_LOCATION
-
-2. Android NDK: http://developer.android.com/tools/sdk/ndk/
- installed in $ANDROID_NDK_LOCATION
-
-= Building =
-
-Set up Android project:
-
-# Creates local.properties, not to be checked in
-$ $ANDROID_SDK_LOCATION/tools/android update project -p .
-
-Build libs/libjpgf.jar:
-
-$ (cd ../../runtime/java && javac org/grammaticalframework/*/*.java && jar -cf ../../ui/android/libs/jpgf.jar org/grammaticalframework/*/*.class)
-
-Build JNI code:
-
-$ cd jni
-$ $ANDROID_NDK_LOCATION/ndk-build
-
-Build the semantic database code:
-
-$ runghc glosses.hs
-
-Build APK:
-
-$ ant debug
-
-
-Install on your device:
-
-$ ant debug install
-
-or:
-
-$ adb install -r bin/MainActivity-debug.apk
-
-
-= Changing the grammar =
-
-1. Replace assets/ResourceDemo.pgf
-
-2. Edit Translator.java to point to the new file and include its metadata
-
-
-= Developing in Eclipse =
-
-1. Install Android ADT
-
-2. Eclipse > File > Import > Existing Projects into Workspace > Next
-
-3. Select root directory...
-
-4. Select GF/src/ui/android
-
-5. Finish
\ No newline at end of file
diff --git a/src/ui/android/ant.properties b/src/ui/android/ant.properties
deleted file mode 100644
index 59ddc9800..000000000
--- a/src/ui/android/ant.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-key.store=/home/krasimir/dg/src/keys/dg_keystore
-key.alias=dg
diff --git a/src/ui/android/assets/help_content.html b/src/ui/android/assets/help_content.html
deleted file mode 100644
index 279a2a963..000000000
--- a/src/ui/android/assets/help_content.html
+++ /dev/null
@@ -1,157 +0,0 @@
-
-
-
-GF Offline Translator :
-text and speech translation for 16 languages with
-quality control. Version 19 April 2017 (beta).
-
-
-Speech input : Tap microphone icon and talk while it is red.
-
-Text input : Select "keyboard" from menu, tap keyboard icon.
-
-Correction : Tap input text and edit.
-
-Alternatives : Tap output text.
-
-Grammar info : Tap any of the alternatives.
-
-Confidence : colour of output text
-
-Green : semantic, probably correct (but has alternatives)
-Yellow : syntactic, often incorrect (has alternatives)
-Light red : chunk-based, probably incorrect (has alternatives)
-Dark red : word-based, often very bad
-
-
-Topics (new, select from menu): Words grouped by semantic categories, with WordNet glosses.
-
-Phrasebook (new, select from menu): Conceptual authoring with the green translations.
-
-
-
-
-More details
-
-GF Offline Translator is based on grammar and semantics. It is compact in size
-and gives control on quality. Its technology is inspired by compilers, which are
-programs that translate computer languages.
-Most other translators for human language are based on
-statistics and have less control of quality and are much bigger, so that
-they require either an internet connection or a huge storage on your phone.
-
-The app indicates translation confidence with colours:
-
- Green :
- semantic translation, should be correct.
- But not necessarily the only correct one.
- You can tap the output to see alternatives.
-
- Yellow :
- syntactic translation, should be grammatically correct.
- But can be very strange in its interpretation and choice of words.
-
- Light red :
- chunk translation, probably incorrect.
- Builds the translation from small pieces.
-
- Dark red :
- word-by-word translation, almost certainly incorrect.
- Builds the translation word by word.
-
-
-The green translations come from a tourist phrasebook, which allows
-you to translate things like "hello" and "how far is the airport from
-the hotel".
-
-
-
-You can translate both speech and text, as selected in the menu in the
-upper right corner. Both kinds of input can be edited with the
-keyboard by first tapping at the input field. This is often needed
-because of speech recognition errors . Changing words
-from upper to lower case may also be needed.
-At the moment, Japanese and Thai input must be separated
-to words, whereas Chinese works without spaces.
-
-
-Translation works between any of the 16 supported languages, which means 240
-language pairs in the current version. But different languages are on different levels of development.
-The following table gives a rough idea of what to expect:
-
-
-
-
-
- coverage quality speed speech
- Bulgarian in only
- Catalan
- Chinese
- Dutch
- English
- Estonian
- Finnish
- French
- German
- Hindi
- Italian
- Japanese*
- Russian
- Spanish
- Swedish
- Thai*
-
-
-* For translation from Japanese and Thai you need to separate each word with a space
-
-
-The speech input and output use Google's voice services. Their status
-can hence change without notice. You can make it more stable by
-installing third-party speech tools, such as SVOX, which provides
-output for most of the listed languages.
-
-
-
-When you tap on a translation you get a screen with alternative translations .
-Tapping on each of the alternatives
-gives you grammatical information :
-an inflection table, if it is a single word,
-and a syntax tree otherwise.
-
-
-
-The app also provides an input method which you can use as
-an alternative keyboard which allows you to do translation from
-other applications, for instance while you are entering SMS or e-mail.
-To activate it go to Settings > Language & input.
-
-
-
-The translation works completely off-line , without
-internet connection, when doing text-based translation.
-Even speech works off-line in some languages,
-but being on-line may give you better
-speech input and output and more languages.
-
-
-You can also install third-party off-line speech engines, such as
-SVOX .
-Consult the voice/language settings on your phone to find the optimal
-speech engines, and restart the app after changing the settings.
-
-
-
-The GF Offline Translator is powered by
-GF , Grammatical Framework.
-It is open-source software,
-built by support from the GF community and from Digital Grammars .
-
-
-
-Digital Grammars is a company that can tailor this app to you needs and provide good
-translation for the kind of vocabulary you need. Just tell us what you want to see
- in the green area!
-
-
-
-
diff --git a/src/ui/android/assets/phrases.xml b/src/ui/android/assets/phrases.xml
deleted file mode 100644
index 847339135..000000000
--- a/src/ui/android/assets/phrases.xml
+++ /dev/null
@@ -1,1035 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ui/android/build.xml b/src/ui/android/build.xml
deleted file mode 100644
index d60bf62f2..000000000
--- a/src/ui/android/build.xml
+++ /dev/null
@@ -1,92 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ui/android/gf-translator-alignment.dot b/src/ui/android/gf-translator-alignment.dot
deleted file mode 100644
index 8eaaa72a5..000000000
--- a/src/ui/android/gf-translator-alignment.dot
+++ /dev/null
@@ -1,60 +0,0 @@
-digraph {
- rankdir=LR ;
- node [shape = record] ;
- bgcolor = "#FFFFFF00" ;
-
- struct0[label = "твоят | телефон | може | да | превежда"] ;
- struct0:n0:e -> struct1:n0:w ;
- struct0:n1:e -> struct1:n1:w ;
- struct0:n2:e -> struct1:n2:w ;
- struct0:n4:e -> struct1:n3:w ;
- struct1[label = "el teu | telèfon | sap | traduir"] ;
- struct1:n0:e -> struct2:n0:w ;
- struct1:n1:e -> struct2:n2:w ;
- struct1:n2:e -> struct2:n3:w ;
- struct1:n3:e -> struct2:n4:w ;
- struct2[label = "你 | 的 | 电 话 | 会 | 翻 译"] ;
- struct2:n0:e -> struct3:n0:w ;
- struct2:n2:e -> struct3:n1:w ;
- struct2:n3:e -> struct3:n2:w ;
- struct2:n4:e -> struct3:n3:w ;
- struct3[label = "je | telefoon | kan | vertalen"] ;
- struct3:n0:e -> struct4:n0:w ;
- struct3:n1:e -> struct4:n1:w ;
- struct3:n2:e -> struct4:n2:w ;
- struct3:n3:e -> struct4:n3:w ;
- struct4[label = "your | phone | can | translate"] ;
- struct4:n1:e -> struct5:n1:w ;
- struct4:n2:e -> struct5:n2:w ;
- struct4:n3:e -> struct5:n3:w ;
- struct5[label = "puhelimesi | osaa | kääntää"] ;
- struct5:n1:e -> struct6:n1:w ;
- struct5:n2:e -> struct6:n2:w ;
- struct5:n3:e -> struct6:n3:w ;
- struct6[label = "ton | téléphone | sait | traduire"] ;
- struct6:n0:e -> struct7:n0:w ;
- struct6:n1:e -> struct7:n1:w ;
- struct6:n2:e -> struct7:n2:w ;
- struct6:n3:e -> struct7:n3:w ;
- struct7[label = "dein | Telefon | kann | übersetzen"] ;
- struct7:n0:e -> struct8:n0:w ;
- struct7:n1:e -> struct8:n1:w ;
- struct7:n2:e -> struct8:n3:w ;
- struct7:n3:e -> struct8:n2:w ;
- struct8[label = "तुम्हारा | फोन | अनुवाद कर | सकता | है"] ;
- struct8:n0:e -> struct9:n1:w ;
- struct8:n1:e -> struct9:n2:w ;
- struct8:n2:e -> struct9:n4:w ;
- struct8:n3:e -> struct9:n3:w ;
- struct9[label = "il | tuo | telefono | sa | tradurre"] ;
- struct9:n1:e -> struct10:n0:w ;
- struct9:n2:e -> struct10:n1:w ;
- struct9:n3:e -> struct10:n2:w ;
- struct9:n4:e -> struct10:n3:w ;
- struct10[label = "tu | teléfono | sabe | traducir"] ;
- struct10:n0:e -> struct11:n0:w ;
- struct10:n1:e -> struct11:n1:w ;
- struct10:n2:e -> struct11:n2:w ;
- struct10:n3:e -> struct11:n3:w ;
- struct11[label = "din | telefon | kan | översätta"] ;
-}
diff --git a/src/ui/android/gf-translator.svg b/src/ui/android/gf-translator.svg
deleted file mode 100644
index 21eee477d..000000000
--- a/src/ui/android/gf-translator.svg
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Offline Translation
- with
- Grammatical Framework
- Grammatical Framework
-
-
diff --git a/src/ui/android/glosses.hs b/src/ui/android/glosses.hs
deleted file mode 100644
index 966ec90aa..000000000
--- a/src/ui/android/glosses.hs
+++ /dev/null
@@ -1,46 +0,0 @@
-import SG
-import PGF2
-import Data.Char
-import Data.List
-
-main = do
- db <- openSG "assets/semantics.db"
- inTransaction db $ do
- ls <- fmap lines $ readFile "../../../lib/src/translator/Dictionary.gf"
- let glosses = [x | Just (fn,gloss) <- map gloss ls, x <- glossTriples fn gloss]
- topics <- fmap (map toTriple . lines) $ readFile "topics.txt"
- sequence_ [insertTriple db s p o | (s,p,o) <- glosses++topics]
- closeSG db
-
-toTriple l =
- case readTriple l of
- Just t -> t
- Nothing -> error ("topics.txt: "++l)
-
-gloss l =
- case words l of
- ("fun":fn:_) -> case dropWhile (/='\t') l of
- '\t':l -> Just (fn,l)
- _ -> Nothing
- _ -> Nothing
-
-glossTriples fn s =
- (if null gs then [] else [(fn_e,gloss,mkStr (merge gs))])++
- (if null es then [] else [(fn_e,example,mkStr (merge (map (init . tail) es)))])
- where
- fn_e = mkApp fn []
- gloss = mkApp "gloss" []
- example = mkApp "example" []
- (es,gs) = partition isExample (splitGloss s)
-
-splitGloss s =
- let (xs,s') = break (==';') s
- in trim xs : case s' of
- ';':s -> splitGloss s
- _ -> []
- where
- trim = reverse . dropWhile isSpace . reverse . dropWhile isSpace
-
-merge = intercalate "; "
-
-isExample s = not (null s) && head s == '"' && last s == '"'
diff --git a/src/ui/android/hlc.svg b/src/ui/android/hlc.svg
deleted file mode 100644
index e61e41c19..000000000
--- a/src/ui/android/hlc.svg
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
- Digital Grammar Logo
-
-
-
diff --git a/src/ui/android/jni/Android.mk b/src/ui/android/jni/Android.mk
deleted file mode 100644
index f1f697bed..000000000
--- a/src/ui/android/jni/Android.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-jni_c_files := jpgf.c jsg.c jni_utils.c
-sg_c_files := sg.c sqlite3Btree.c
-pgf_c_files := data.c expr.c graphviz.c linearizer.c literals.c parser.c parseval.c pgf.c printer.c reader.c \
-reasoner.c evaluator.c jit.c typechecker.c lookup.c aligner.c writer.c
-gu_c_files := assert.c choice.c exn.c fun.c in.c map.c out.c utf8.c \
-bits.c defs.c enum.c file.c hash.c mem.c prime.c seq.c string.c ucs.c variant.c
-
-LOCAL_MODULE := jpgf
-LOCAL_SRC_FILES := $(addprefix ../../../runtime/java/, $(jni_c_files)) \
- $(addprefix ../../../runtime/c/sg/, $(sg_c_files)) \
- $(addprefix ../../../runtime/c/pgf/, $(pgf_c_files)) \
- $(addprefix ../../../runtime/c/gu/, $(gu_c_files))
-LOCAL_C_INCLUDES := ../../../runtime/c
-
-include $(BUILD_SHARED_LIBRARY)
-
-$(realpath ../obj/local/armeabi/objs/jpgf/__/__/__/runtime/c/pgf/jit.o): lightning
-$(realpath ../obj/local/armeabi/objs-debug/jpgf/__/__/__/runtime/c/pgf/jit.o): lightning
-
-lightning:
- ln -s -f arm/asm.h ../../../runtime/c/pgf/lightning/asm.h
- ln -s -f arm/core.h ../../../runtime/c/pgf/lightning/core.h
- ln -s -f arm/fp.h ../../../runtime/c/pgf/lightning/fp.h
- ln -s -f arm/funcs.h ../../../runtime/c/pgf/lightning/funcs.h
diff --git a/src/ui/android/jni/Application.mk b/src/ui/android/jni/Application.mk
deleted file mode 100644
index 6a9876332..000000000
--- a/src/ui/android/jni/Application.mk
+++ /dev/null
@@ -1,3 +0,0 @@
-APP_PLATFORM := android-8
-APP_CFLAGS := -std=gnu99
-APP_OPTIM := release
diff --git a/src/ui/android/proguard-project.txt b/src/ui/android/proguard-project.txt
deleted file mode 100644
index f2fe1559a..000000000
--- a/src/ui/android/proguard-project.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-# To enable ProGuard in your project, edit project.properties
-# to define the proguard.config property as described in that file.
-#
-# Add project specific ProGuard rules here.
-# By default, the flags in this file are appended to flags specified
-# in ${sdk.dir}/tools/proguard/proguard-android.txt
-# You can edit the include path and order by changing the ProGuard
-# include property in project.properties.
-#
-# For more details, see
-# http://developer.android.com/guide/developing/tools/proguard.html
-
-# Add any project specific keep options here:
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-# public *;
-#}
diff --git a/src/ui/android/project.properties b/src/ui/android/project.properties
deleted file mode 100644
index 6e18427a4..000000000
--- a/src/ui/android/project.properties
+++ /dev/null
@@ -1,14 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system edit
-# "ant.properties", and override values to adapt the script to your
-# project structure.
-#
-# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
-#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
-
-# Project target.
-target=android-21
diff --git a/src/ui/android/res/drawable-hdpi/btn_close.png b/src/ui/android/res/drawable-hdpi/btn_close.png
deleted file mode 100644
index 47f11e5bf..000000000
Binary files a/src/ui/android/res/drawable-hdpi/btn_close.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-hdpi/close_arrow.png b/src/ui/android/res/drawable-hdpi/close_arrow.png
deleted file mode 100644
index bf280a05a..000000000
Binary files a/src/ui/android/res/drawable-hdpi/close_arrow.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-hdpi/ic_action_switch.png b/src/ui/android/res/drawable-hdpi/ic_action_switch.png
deleted file mode 100644
index 5449a32b8..000000000
Binary files a/src/ui/android/res/drawable-hdpi/ic_action_switch.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-hdpi/ic_app.png b/src/ui/android/res/drawable-hdpi/ic_app.png
deleted file mode 100644
index 8d9bdd820..000000000
Binary files a/src/ui/android/res/drawable-hdpi/ic_app.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-hdpi/ic_drawer.png b/src/ui/android/res/drawable-hdpi/ic_drawer.png
deleted file mode 100644
index c59f601ca..000000000
Binary files a/src/ui/android/res/drawable-hdpi/ic_drawer.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-hdpi/ic_keyboard.png b/src/ui/android/res/drawable-hdpi/ic_keyboard.png
deleted file mode 100644
index ce257a269..000000000
Binary files a/src/ui/android/res/drawable-hdpi/ic_keyboard.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-hdpi/ic_mic.png b/src/ui/android/res/drawable-hdpi/ic_mic.png
deleted file mode 100644
index f79ff489b..000000000
Binary files a/src/ui/android/res/drawable-hdpi/ic_mic.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-hdpi/ic_search_black_24dp.png b/src/ui/android/res/drawable-hdpi/ic_search_black_24dp.png
deleted file mode 100644
index c593e7ad8..000000000
Binary files a/src/ui/android/res/drawable-hdpi/ic_search_black_24dp.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-hdpi/open_arrow.png b/src/ui/android/res/drawable-hdpi/open_arrow.png
deleted file mode 100644
index ec7453797..000000000
Binary files a/src/ui/android/res/drawable-hdpi/open_arrow.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-hdpi/sym_keyboard_delete.png b/src/ui/android/res/drawable-hdpi/sym_keyboard_delete.png
deleted file mode 100644
index 5139c7179..000000000
Binary files a/src/ui/android/res/drawable-hdpi/sym_keyboard_delete.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-hdpi/sym_keyboard_return.png b/src/ui/android/res/drawable-hdpi/sym_keyboard_return.png
deleted file mode 100644
index 5a5670c32..000000000
Binary files a/src/ui/android/res/drawable-hdpi/sym_keyboard_return.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-hdpi/sym_keyboard_search.png b/src/ui/android/res/drawable-hdpi/sym_keyboard_search.png
deleted file mode 100644
index e72cde3bb..000000000
Binary files a/src/ui/android/res/drawable-hdpi/sym_keyboard_search.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-hdpi/sym_keyboard_shift.png b/src/ui/android/res/drawable-hdpi/sym_keyboard_shift.png
deleted file mode 100644
index 275769618..000000000
Binary files a/src/ui/android/res/drawable-hdpi/sym_keyboard_shift.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-hdpi/sym_keyboard_space.png b/src/ui/android/res/drawable-hdpi/sym_keyboard_space.png
deleted file mode 100644
index cef2daa5d..000000000
Binary files a/src/ui/android/res/drawable-hdpi/sym_keyboard_space.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-mdpi/ic_action_switch.png b/src/ui/android/res/drawable-mdpi/ic_action_switch.png
deleted file mode 100644
index ecf7d0347..000000000
Binary files a/src/ui/android/res/drawable-mdpi/ic_action_switch.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-mdpi/ic_app.png b/src/ui/android/res/drawable-mdpi/ic_app.png
deleted file mode 100644
index 923d0fe91..000000000
Binary files a/src/ui/android/res/drawable-mdpi/ic_app.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-mdpi/ic_drawer.png b/src/ui/android/res/drawable-mdpi/ic_drawer.png
deleted file mode 100644
index 1ed2c56ee..000000000
Binary files a/src/ui/android/res/drawable-mdpi/ic_drawer.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-mdpi/ic_mic.png b/src/ui/android/res/drawable-mdpi/ic_mic.png
deleted file mode 100644
index 8f7f55cf9..000000000
Binary files a/src/ui/android/res/drawable-mdpi/ic_mic.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-mdpi/ic_search_black_24dp.png b/src/ui/android/res/drawable-mdpi/ic_search_black_24dp.png
deleted file mode 100644
index 6b1634323..000000000
Binary files a/src/ui/android/res/drawable-mdpi/ic_search_black_24dp.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-mdpi/sym_keyboard_delete.png b/src/ui/android/res/drawable-mdpi/sym_keyboard_delete.png
deleted file mode 100644
index 6cee59682..000000000
Binary files a/src/ui/android/res/drawable-mdpi/sym_keyboard_delete.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-mdpi/sym_keyboard_done.png b/src/ui/android/res/drawable-mdpi/sym_keyboard_done.png
deleted file mode 100644
index c0d6d1394..000000000
Binary files a/src/ui/android/res/drawable-mdpi/sym_keyboard_done.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-mdpi/sym_keyboard_return.png b/src/ui/android/res/drawable-mdpi/sym_keyboard_return.png
deleted file mode 100644
index cbe2b152f..000000000
Binary files a/src/ui/android/res/drawable-mdpi/sym_keyboard_return.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-mdpi/sym_keyboard_search.png b/src/ui/android/res/drawable-mdpi/sym_keyboard_search.png
deleted file mode 100644
index 127755d6b..000000000
Binary files a/src/ui/android/res/drawable-mdpi/sym_keyboard_search.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-mdpi/sym_keyboard_shift.png b/src/ui/android/res/drawable-mdpi/sym_keyboard_shift.png
deleted file mode 100644
index d05962846..000000000
Binary files a/src/ui/android/res/drawable-mdpi/sym_keyboard_shift.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-mdpi/sym_keyboard_space.png b/src/ui/android/res/drawable-mdpi/sym_keyboard_space.png
deleted file mode 100644
index 09b94d9e6..000000000
Binary files a/src/ui/android/res/drawable-mdpi/sym_keyboard_space.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-xhdpi/ic_action_switch.png b/src/ui/android/res/drawable-xhdpi/ic_action_switch.png
deleted file mode 100644
index b5da00fb2..000000000
Binary files a/src/ui/android/res/drawable-xhdpi/ic_action_switch.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-xhdpi/ic_app.png b/src/ui/android/res/drawable-xhdpi/ic_app.png
deleted file mode 100644
index f7eb06682..000000000
Binary files a/src/ui/android/res/drawable-xhdpi/ic_app.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-xhdpi/ic_dictionary.png b/src/ui/android/res/drawable-xhdpi/ic_dictionary.png
deleted file mode 100644
index 985644ebd..000000000
Binary files a/src/ui/android/res/drawable-xhdpi/ic_dictionary.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-xhdpi/ic_drawer.png b/src/ui/android/res/drawable-xhdpi/ic_drawer.png
deleted file mode 100644
index a5fa74def..000000000
Binary files a/src/ui/android/res/drawable-xhdpi/ic_drawer.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-xhdpi/ic_mic.png b/src/ui/android/res/drawable-xhdpi/ic_mic.png
deleted file mode 100644
index 13d21274a..000000000
Binary files a/src/ui/android/res/drawable-xhdpi/ic_mic.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-xhdpi/ic_search_black_24dp.png b/src/ui/android/res/drawable-xhdpi/ic_search_black_24dp.png
deleted file mode 100644
index 638190268..000000000
Binary files a/src/ui/android/res/drawable-xhdpi/ic_search_black_24dp.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-xxhdpi/ic_app.png b/src/ui/android/res/drawable-xxhdpi/ic_app.png
deleted file mode 100644
index 6154d852a..000000000
Binary files a/src/ui/android/res/drawable-xxhdpi/ic_app.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-xxhdpi/ic_drawer.png b/src/ui/android/res/drawable-xxhdpi/ic_drawer.png
deleted file mode 100644
index 9c4685d6e..000000000
Binary files a/src/ui/android/res/drawable-xxhdpi/ic_drawer.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-xxhdpi/ic_search_black_24dp.png b/src/ui/android/res/drawable-xxhdpi/ic_search_black_24dp.png
deleted file mode 100644
index 3ae490ef9..000000000
Binary files a/src/ui/android/res/drawable-xxhdpi/ic_search_black_24dp.png and /dev/null differ
diff --git a/src/ui/android/res/drawable-xxxhdpi/ic_search_black_24dp.png b/src/ui/android/res/drawable-xxxhdpi/ic_search_black_24dp.png
deleted file mode 100644
index 21be57299..000000000
Binary files a/src/ui/android/res/drawable-xxxhdpi/ic_search_black_24dp.png and /dev/null differ
diff --git a/src/ui/android/res/drawable/first_person_utterance_bg.xml b/src/ui/android/res/drawable/first_person_utterance_bg.xml
deleted file mode 100644
index acdf9ab92..000000000
--- a/src/ui/android/res/drawable/first_person_utterance_bg.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/ui/android/res/drawable/grid_phrasebook_button.xml b/src/ui/android/res/drawable/grid_phrasebook_button.xml
deleted file mode 100644
index 21a6ac127..000000000
--- a/src/ui/android/res/drawable/grid_phrasebook_button.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/ui/android/res/drawable/ic_volume_up_black_18dp.png b/src/ui/android/res/drawable/ic_volume_up_black_18dp.png
deleted file mode 100644
index 992d2c452..000000000
Binary files a/src/ui/android/res/drawable/ic_volume_up_black_18dp.png and /dev/null differ
diff --git a/src/ui/android/res/drawable/second_person_best_utterance_bg.xml b/src/ui/android/res/drawable/second_person_best_utterance_bg.xml
deleted file mode 100644
index 0c60864b9..000000000
--- a/src/ui/android/res/drawable/second_person_best_utterance_bg.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/ui/android/res/drawable/second_person_chunk_utterance_bg.xml b/src/ui/android/res/drawable/second_person_chunk_utterance_bg.xml
deleted file mode 100644
index d10d67122..000000000
--- a/src/ui/android/res/drawable/second_person_chunk_utterance_bg.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/ui/android/res/drawable/second_person_utterance_bg.xml b/src/ui/android/res/drawable/second_person_utterance_bg.xml
deleted file mode 100644
index e07cc10b3..000000000
--- a/src/ui/android/res/drawable/second_person_utterance_bg.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/ui/android/res/drawable/second_person_worst_utterance_bg.xml b/src/ui/android/res/drawable/second_person_worst_utterance_bg.xml
deleted file mode 100644
index f4effe3bc..000000000
--- a/src/ui/android/res/drawable/second_person_worst_utterance_bg.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/ui/android/res/layout/activity_help.xml b/src/ui/android/res/layout/activity_help.xml
deleted file mode 100644
index 3cb88a569..000000000
--- a/src/ui/android/res/layout/activity_help.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
diff --git a/src/ui/android/res/layout/activity_lexical_entry.xml b/src/ui/android/res/layout/activity_lexical_entry.xml
deleted file mode 100644
index fa49f252b..000000000
--- a/src/ui/android/res/layout/activity_lexical_entry.xml
+++ /dev/null
@@ -1,80 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ui/android/res/layout/activity_main.xml b/src/ui/android/res/layout/activity_main.xml
deleted file mode 100644
index b77fe5857..000000000
--- a/src/ui/android/res/layout/activity_main.xml
+++ /dev/null
@@ -1,91 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/ui/android/res/layout/activity_navigation.xml b/src/ui/android/res/layout/activity_navigation.xml
deleted file mode 100644
index 44311b90d..000000000
--- a/src/ui/android/res/layout/activity_navigation.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
-
diff --git a/src/ui/android/res/layout/activity_semantic_graph.xml b/src/ui/android/res/layout/activity_semantic_graph.xml
deleted file mode 100644
index 004e22a7c..000000000
--- a/src/ui/android/res/layout/activity_semantic_graph.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ui/android/res/layout/alternative_item.xml b/src/ui/android/res/layout/alternative_item.xml
deleted file mode 100644
index f35d1b938..000000000
--- a/src/ui/android/res/layout/alternative_item.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/ui/android/res/layout/checkbox_input_list_item.xml b/src/ui/android/res/layout/checkbox_input_list_item.xml
deleted file mode 100644
index 255d0ae8d..000000000
--- a/src/ui/android/res/layout/checkbox_input_list_item.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
diff --git a/src/ui/android/res/layout/first_person_utterance.xml b/src/ui/android/res/layout/first_person_utterance.xml
deleted file mode 100644
index 97171149c..000000000
--- a/src/ui/android/res/layout/first_person_utterance.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
diff --git a/src/ui/android/res/layout/fragment_phrase_list.xml b/src/ui/android/res/layout/fragment_phrase_list.xml
deleted file mode 100644
index 1868da31c..000000000
--- a/src/ui/android/res/layout/fragment_phrase_list.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
diff --git a/src/ui/android/res/layout/fragment_translator.xml b/src/ui/android/res/layout/fragment_translator.xml
deleted file mode 100644
index 6b6584f98..000000000
--- a/src/ui/android/res/layout/fragment_translator.xml
+++ /dev/null
@@ -1,60 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ui/android/res/layout/input.xml b/src/ui/android/res/layout/input.xml
deleted file mode 100644
index fdef07a53..000000000
--- a/src/ui/android/res/layout/input.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
diff --git a/src/ui/android/res/layout/keyboard_languages_options.xml b/src/ui/android/res/layout/keyboard_languages_options.xml
deleted file mode 100644
index 17512df19..000000000
--- a/src/ui/android/res/layout/keyboard_languages_options.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/src/ui/android/res/layout/languages_item.xml b/src/ui/android/res/layout/languages_item.xml
deleted file mode 100644
index d5f47ab27..000000000
--- a/src/ui/android/res/layout/languages_item.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
diff --git a/src/ui/android/res/layout/lexical_item.xml b/src/ui/android/res/layout/lexical_item.xml
deleted file mode 100644
index 1d3835e54..000000000
--- a/src/ui/android/res/layout/lexical_item.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/src/ui/android/res/layout/number_input_list_item.xml b/src/ui/android/res/layout/number_input_list_item.xml
deleted file mode 100644
index a3cfa07e5..000000000
--- a/src/ui/android/res/layout/number_input_list_item.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/ui/android/res/layout/phrase_list_item.xml b/src/ui/android/res/layout/phrase_list_item.xml
deleted file mode 100644
index f812ad871..000000000
--- a/src/ui/android/res/layout/phrase_list_item.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
diff --git a/src/ui/android/res/layout/second_person_utterance.xml b/src/ui/android/res/layout/second_person_utterance.xml
deleted file mode 100644
index 416d85328..000000000
--- a/src/ui/android/res/layout/second_person_utterance.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
diff --git a/src/ui/android/res/layout/spinner_input_list_item.xml b/src/ui/android/res/layout/spinner_input_list_item.xml
deleted file mode 100644
index be07004f4..000000000
--- a/src/ui/android/res/layout/spinner_input_list_item.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/src/ui/android/res/menu/main.xml b/src/ui/android/res/menu/main.xml
deleted file mode 100644
index f36095749..000000000
--- a/src/ui/android/res/menu/main.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
diff --git a/src/ui/android/res/values-sw600dp/dimens.xml b/src/ui/android/res/values-sw600dp/dimens.xml
deleted file mode 100644
index 44f01db75..000000000
--- a/src/ui/android/res/values-sw600dp/dimens.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
diff --git a/src/ui/android/res/values-sw720dp-land/dimens.xml b/src/ui/android/res/values-sw720dp-land/dimens.xml
deleted file mode 100644
index 61e3fa8fb..000000000
--- a/src/ui/android/res/values-sw720dp-land/dimens.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
- 128dp
-
-
diff --git a/src/ui/android/res/values-v11/styles.xml b/src/ui/android/res/values-v11/styles.xml
deleted file mode 100644
index 3c02242ad..000000000
--- a/src/ui/android/res/values-v11/styles.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
diff --git a/src/ui/android/res/values-v14/styles.xml b/src/ui/android/res/values-v14/styles.xml
deleted file mode 100644
index a91fd0372..000000000
--- a/src/ui/android/res/values-v14/styles.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
diff --git a/src/ui/android/res/values/attrs.xml b/src/ui/android/res/values/attrs.xml
deleted file mode 100644
index debd08fa0..000000000
--- a/src/ui/android/res/values/attrs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/src/ui/android/res/values/colors.xml b/src/ui/android/res/values/colors.xml
deleted file mode 100644
index e7dbbada4..000000000
--- a/src/ui/android/res/values/colors.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
- #FF000000
- #FFE35900
- #ff808080
- #ffffffff
- - #75CD75
- - #616161
-
diff --git a/src/ui/android/res/values/dimens.xml b/src/ui/android/res/values/dimens.xml
deleted file mode 100644
index 04289dc79..000000000
--- a/src/ui/android/res/values/dimens.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
- 16dp
- 16dp
- 50dip
- 25sp
- 6sp
-
-
diff --git a/src/ui/android/res/values/strings.xml b/src/ui/android/res/values/strings.xml
deleted file mode 100644
index 8281a1353..000000000
--- a/src/ui/android/res/values/strings.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
- GF Offline Translator
-
- Microphone
- Switch languages
- Opening
- Speech Input
- Keyboard Input
- Semantic Graph
- Help
- org.grammaticalframework.ui.android.GLOBAL_PREFERENCES
-
- authority_key
- source_key
- target_key
- alternatives_key
-
-
- Done
- Go
- Next
- Previous
- Send
-
-
- normalKeyboardMode
- internalKeyboardMode
-
- Search word:
- Search for words in the lexicon
-
- Topics
- Open topics
- Close topics
-
- Phrasebook
-
diff --git a/src/ui/android/res/values/styles.xml b/src/ui/android/res/values/styles.xml
deleted file mode 100644
index c839d30a9..000000000
--- a/src/ui/android/res/values/styles.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ui/android/res/xml/cyrillic.xml b/src/ui/android/res/xml/cyrillic.xml
deleted file mode 100644
index b699d9c19..000000000
--- a/src/ui/android/res/xml/cyrillic.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ui/android/res/xml/devanagari_page1.xml b/src/ui/android/res/xml/devanagari_page1.xml
deleted file mode 100644
index 14e87a4f3..000000000
--- a/src/ui/android/res/xml/devanagari_page1.xml
+++ /dev/null
@@ -1,67 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/ui/android/res/xml/devanagari_page2.xml b/src/ui/android/res/xml/devanagari_page2.xml
deleted file mode 100644
index 982adb277..000000000
--- a/src/ui/android/res/xml/devanagari_page2.xml
+++ /dev/null
@@ -1,67 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- "आ"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/ui/android/res/xml/method.xml b/src/ui/android/res/xml/method.xml
deleted file mode 100644
index af83761ca..000000000
--- a/src/ui/android/res/xml/method.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/src/ui/android/res/xml/nordic.xml b/src/ui/android/res/xml/nordic.xml
deleted file mode 100644
index 80b1d6e51..000000000
--- a/src/ui/android/res/xml/nordic.xml
+++ /dev/null
@@ -1,77 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ui/android/res/xml/popup_keyboard.xml b/src/ui/android/res/xml/popup_keyboard.xml
deleted file mode 100644
index 521d3d278..000000000
--- a/src/ui/android/res/xml/popup_keyboard.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/src/ui/android/res/xml/qwerty.xml b/src/ui/android/res/xml/qwerty.xml
deleted file mode 100644
index a0021d4b4..000000000
--- a/src/ui/android/res/xml/qwerty.xml
+++ /dev/null
@@ -1,74 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ui/android/res/xml/searchable.xml b/src/ui/android/res/xml/searchable.xml
deleted file mode 100644
index 7e7b6a846..000000000
--- a/src/ui/android/res/xml/searchable.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
diff --git a/src/ui/android/res/xml/symbols_page1.xml b/src/ui/android/res/xml/symbols_page1.xml
deleted file mode 100644
index 509bb79ae..000000000
--- a/src/ui/android/res/xml/symbols_page1.xml
+++ /dev/null
@@ -1,73 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/ui/android/res/xml/symbols_page2.xml b/src/ui/android/res/xml/symbols_page2.xml
deleted file mode 100644
index b55e6f521..000000000
--- a/src/ui/android/res/xml/symbols_page2.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ui/android/res/xml/thai_page1.xml b/src/ui/android/res/xml/thai_page1.xml
deleted file mode 100644
index bcc2aee39..000000000
--- a/src/ui/android/res/xml/thai_page1.xml
+++ /dev/null
@@ -1,86 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ui/android/res/xml/thai_page2.xml b/src/ui/android/res/xml/thai_page2.xml
deleted file mode 100644
index 00e76f525..000000000
--- a/src/ui/android/res/xml/thai_page2.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/ASR.java b/src/ui/android/src/org/grammaticalframework/ui/android/ASR.java
deleted file mode 100644
index 8d683e1f5..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/ASR.java
+++ /dev/null
@@ -1,240 +0,0 @@
-
-package org.grammaticalframework.ui.android;
-
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.speech.RecognitionListener;
-import android.speech.RecognizerIntent;
-import android.speech.SpeechRecognizer;
-import android.text.TextUtils;
-import android.util.Log;
-
-import java.util.ArrayList;
-
-/**
- * Convenience wrapper around the {@link SpeechRecognizer} API.
- */
-public class ASR {
-
- private static final boolean DBG = false;
- private static final String TAG = "ASR";
-
- private final Context mContext;
-
- private SpeechRecognizer mSpeechRecognizer;
-
- private String mLanguage = null;
-
- private State mState = State.IDLE;
-
- private Listener mListener;
-
- public static enum State {
- IDLE, INITIALIZING, WAITING_FOR_SPEECH, RECORDING, WAITING_FOR_RESULTS;
- }
-
- public ASR(Context context) {
- mContext = context;
- if (SpeechRecognizer.isRecognitionAvailable(context)) {
- mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(context);
- mSpeechRecognizer.setRecognitionListener(new MyRecognitionListener());
- }
- }
-
- public void setListener(Listener listener) {
- mListener = listener;
- }
-
- public void setLanguage(String language) {
- mLanguage = language;
- }
-
- public void startRecognition() {
- Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
- if (!TextUtils.isEmpty(mLanguage)) {
- intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, mLanguage);
- }
- intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
- RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
- intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 2);
- intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
- // Weird, this shouldn't be required, but on ICS it seems to be
- intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
- mContext.getPackageName());
-
- mSpeechRecognizer.startListening(intent);
- setState(State.INITIALIZING);
- }
-
- public void stopRecognition() {
- mSpeechRecognizer.stopListening();
- setState(State.IDLE);
- }
-
- public boolean isRunning() {
- return mState != State.IDLE;
- }
-
- private void setState(State newState) {
- if (DBG) Log.d(TAG, "Entering state: " + newState);
- mState = newState;
- if (mListener != null) {
- mListener.onStateChanged(mState);
- }
- }
-
- public State getState() {
- return mState;
- }
-
- public void destroy() {
- if (mSpeechRecognizer != null) {
- mSpeechRecognizer.destroy();
- mSpeechRecognizer = null;
- }
- }
-
- private void handlePartialInput(String text) {
- if (mListener != null) {
- mListener.onPartialInput(text);
- }
- }
-
- private void handleSpeechInput(String text) {
- if (mListener != null) {
- mListener.onSpeechInput(text);
- }
- }
-
- private class MyRecognitionListener implements RecognitionListener {
- @Override
- public void onReadyForSpeech(Bundle params) {
- if (DBG) Log.d(TAG, "onReadyForSpeech");
- setState(State.WAITING_FOR_SPEECH);
- }
-
- @Override
- public void onBeginningOfSpeech() {
- if (DBG) Log.d(TAG, "onBeginningOfSpeech");
- setState(State.RECORDING);
- }
-
- @Override
- public void onBufferReceived(byte[] buffer) {
- // Ignore
- }
-
- @Override
- public void onRmsChanged(float rmsdB) {
- if (DBG) Log.d(TAG, "onRmsChanged(" + rmsdB + ")");
- }
-
- @Override
- public void onEndOfSpeech() {
- if (DBG) Log.d(TAG, "onEndOfSpeech");
- setState(State.WAITING_FOR_RESULTS);
- }
-
- @Override
- public void onError(int error) {
- if (DBG) Log.d(TAG, "Error: " + errorMessage(error) + " (" + error + ")");
- setState(State.IDLE);
- }
-
- private String errorMessage(int speechRecognizerError) {
- switch(speechRecognizerError) {
- case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
- return "network timeout";
- case SpeechRecognizer.ERROR_NETWORK:
- return "network";
- case SpeechRecognizer.ERROR_AUDIO:
- return "audio";
- case SpeechRecognizer.ERROR_SERVER:
- return "server";
- case SpeechRecognizer.ERROR_CLIENT:
- return "client";
- case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
- return "timeout waiting for speech";
- case SpeechRecognizer.ERROR_NO_MATCH:
- return "no match found";
- case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:
- return "recognizer busy";
- case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:
- return "insufficient permissions (missing RECORD_AUDIO?)";
- default:
- return "unknown";
- }
- }
-
- @Override
- public void onEvent(int eventType, Bundle params) {
- if (DBG) Log.d(TAG, "onEvent(" + eventType + ")");
- }
-
- @Override
- public void onPartialResults(Bundle bundle) {
- if (DBG) {
- StringBuilder sb = new StringBuilder();
- sb.append("onPartialResults:");
- appendResults(sb, bundle);
- Log.d(TAG, sb.toString());
- }
-
- String result = getResult(bundle);
- if (!TextUtils.isEmpty(result)) {
- handlePartialInput(result);
- }
- }
-
- @Override
- public void onResults(Bundle bundle) {
- if (DBG) {
- StringBuilder sb = new StringBuilder();
- sb.append("onResults:");
- appendResults(sb, bundle);
- Log.d(TAG, sb.toString());
- }
-
- setState(State.IDLE);
-
- String result = getResult(bundle);
- if (!TextUtils.isEmpty(result)) {
- handleSpeechInput(result);
- }
- }
-
- private String getResult(Bundle bundle) {
- ArrayList results =
- bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
- if (results != null && !results.isEmpty()) {
- return results.get(0);
- } else {
- return null;
- }
- }
-
- private void appendResults(StringBuilder sb, Bundle bundle) {
- ArrayList results =
- bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
- float[] scores = bundle.getFloatArray(SpeechRecognizer.CONFIDENCE_SCORES);
-
- if (results != null) {
- int size = results.size();
- for (int i = 0; i < size; i++) {
- sb.append("\n> ").append(results.get(i));
- if (scores != null && i < scores.length) {
- sb.append(" [").append(scores[i]).append("]");
- }
- }
- }
- }
- }
-
- public interface Listener {
- void onPartialInput(String input);
- void onSpeechInput(String input);
- void onStateChanged(State newState);
- }
-
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/AlternativesActivity.java b/src/ui/android/src/org/grammaticalframework/ui/android/AlternativesActivity.java
deleted file mode 100644
index 4f39a04e1..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/AlternativesActivity.java
+++ /dev/null
@@ -1,674 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import java.util.*;
-
-import android.app.Activity;
-import android.app.ListActivity;
-import android.content.Context;
-import android.content.res.Configuration;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.view.*;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.view.ViewGroup.LayoutParams;
-import android.view.MenuItem;
-import android.view.LayoutInflater;
-import android.webkit.WebView;
-import android.widget.BaseAdapter;
-import android.widget.ListAdapter;
-import android.widget.ArrayAdapter;
-import android.widget.ImageView;
-import android.widget.RelativeLayout;
-import android.widget.TextView;
-import android.widget.CheckBox;
-import android.widget.CompoundButton;
-import android.widget.ListView;
-import android.widget.AdapterView;
-import android.util.Log;
-import android.support.v4.widget.DrawerLayout;
-import android.support.v4.app.ActionBarDrawerToggle;
-
-import org.grammaticalframework.pgf.*;
-import org.grammaticalframework.ui.android.LanguageSelector.OnLanguageSelectedListener;
-
-public class AlternativesActivity extends ListActivity {
-
- private Translator mTranslator;
- private LanguageSelector mShowLanguageView;
- private View mProgressBarView = null;
- private AlternativesAdapter mAdapter = null;
- private DrawerLayout mDrawerLayout;
- private ListView mDrawerList;
- private ActionBarDrawerToggle mDrawerToggle;
-
- /** Called when the activity is first created. */
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_lexical_entry);
-
- mTranslator = ((GFTranslator) getApplicationContext()).getTranslator();
-
- mShowLanguageView = (LanguageSelector) findViewById(R.id.show_language);
- mShowLanguageView.setLanguages(mTranslator.getAvailableLanguages());
- mShowLanguageView.setOnLanguageSelectedListener(new OnLanguageSelectedListener() {
- @Override
- public void onLanguageSelected(final Language language) {
- new AsyncTask() {
- @Override
- protected void onPreExecute() {
- showProgressBar();
- }
-
- @Override
- protected Void doInBackground(Void... params) {
- mTranslator.setTargetLanguage(language);
- mTranslator.isTargetLanguageLoaded();
- return null;
- }
-
- @Override
- protected void onPostExecute(Void result) {
- mAdapter.notifyDataSetChanged();
- collapse();
- hideProgressBar();
- }
- }.execute();
- }
- });
-
- mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
- mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
- R.drawable.ic_drawer,
- R.string.topics_open,
- R.string.topics_close);
- mDrawerLayout.setDrawerListener(mDrawerToggle);
-
- getActionBar().setDisplayHomeAsUpEnabled(true);
- getActionBar().setHomeButtonEnabled(true);
-
- TextView descrView = (TextView) findViewById(R.id.lexical_desc);
-
- if (getIntent().getData() != null) {
- String authority = getIntent().getData().getAuthority();
- String source = getIntent().getData().getQueryParameter("source");
-
- List analyses = new ArrayList();
- for (String an : getIntent().getData().getQueryParameters("alternative")) {
- analyses.add(Expr.readExpr(an));
- }
- descrView.setText(source);
-
- mAdapter = new AlternativesAdapter(this, authority, analyses);
- } else {
- mDrawerLayout.openDrawer(Gravity.LEFT);
-
- mAdapter = new AlternativesAdapter(this, Translator.WORDS);
- }
-
- expandedView = null;
- setListAdapter(mAdapter);
-
- mDrawerList = (ListView) findViewById(R.id.topics_list);
- mDrawerList.setAdapter(mAdapter.getTopicsAdapter());
-
- mProgressBarView = findViewById(R.id.progressBarView);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
-
- mShowLanguageView.setSelectedLanguage(mTranslator.getTargetLanguage());
- }
-
- private void showProgressBar() {
- mProgressBarView.setVisibility(View.VISIBLE);
- }
-
- private void hideProgressBar() {
- mProgressBarView.setVisibility(View.GONE);
- }
-
- private View expandedView;
-
- private void collapse() {
- if (expandedView == null)
- return;
-
- ImageView arrow = (ImageView) expandedView.findViewById(R.id.arrow);
- arrow.setImageResource(R.drawable.open_arrow);
-
- View view = (View) expandedView.findViewById(R.id.desc_details);
- ((RelativeLayout) expandedView).removeView(view);
-
- TextView textView = (TextView) expandedView.findViewById(R.id.abstract_tree);
- if (textView != null)
- ((RelativeLayout) expandedView).removeView(textView);
-
- expandedView = null;
- }
-
- private void expandWord(View view, Expr lemma) {
- String html = mTranslator.getInflectionTable(lemma);
- if (html == null)
- return;
-
- ImageView arrow = (ImageView) view.findViewById(R.id.arrow);
- arrow.setImageResource(R.drawable.close_arrow);
-
- WebView inflectionView = (WebView) view.findViewById(R.id.desc_details);
- if (inflectionView == null) {
- inflectionView = new WebView(this);
- inflectionView.setId(R.id.desc_details);
- RelativeLayout.LayoutParams params =
- new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
- params.addRule(RelativeLayout.BELOW, R.id.lexical_desc);
- ((RelativeLayout) view).addView(inflectionView, params);
- }
-
- inflectionView.loadData(html, "text/html; charset=UTF-8", null);
-
- expandedView = view;
- }
-
- private void expandSentence(View view, Expr expr) {
- ImageView arrow = (ImageView) view.findViewById(R.id.arrow);
- arrow.setImageResource(R.drawable.close_arrow);
-
- ParseTreeView parseView = (ParseTreeView) view.findViewById(R.id.desc_details);
- if (parseView == null) {
- parseView = new ParseTreeView(this);
- parseView.setId(R.id.desc_details);
- RelativeLayout.LayoutParams params =
- new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
- params.addRule(RelativeLayout.BELOW, R.id.alternative_desc);
- ((RelativeLayout) view).addView(parseView, params);
- }
-
- Object[] brackets = mTranslator.bracketedLinearize(expr);
- if (brackets[0] instanceof Bracket) {
- Bracket b = (Bracket) brackets[0];
- if (b.children[0].equals("*") ||
- b.children[0].equals("+")) {
- Object[] children = new Object[b.children.length-1];
- for (int i = 1; i < b.children.length; i++)
- children[i-1] = b.children[i];
- b = new Bracket(b.cat, b.fun, b.fid, b.lindex, children);
- brackets[0] = b;
- }
- }
- parseView.setBrackets(brackets);
-
- TextView textView = (TextView) view.findViewById(R.id.abstract_tree);
- if (textView == null) {
- textView = new TextView(this);
- textView.setId(R.id.abstract_tree);
- textView.setTextSize(15);
- RelativeLayout.LayoutParams params =
- new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
- params.addRule(RelativeLayout.BELOW, R.id.desc_details);
- ((RelativeLayout) view).addView(textView, params);
- }
- textView.setText(expr.toString());
-
- expandedView = view;
- }
-
- private class Topic {
- public String name;
- public Expr expr;
- public boolean isChecked;
- public boolean isAvailable;
-
- public Topic(String name, Expr expr) {
- this.name = name;
- this.expr = expr;
- this.isChecked = false;
- this.isAvailable = true;
- }
- }
-
- private class AlternativesAdapter extends BaseAdapter implements ListAdapter {
- /**
- * Contains the list of objects that represent the alternatives
- */
- private List mAlternatives;
-
- private Context mContext;
-
- // A copy of the original mAlternatives array, initialized from and then used instead as soon as
- // a topic filtering is applied. mAlternatives will then only contain the filtered values.
- private ArrayList mOriginalAlternatives;
-
- private LayoutInflater mInflater;
-
- private String mAuthority;
-
- /**
- * A list of lists of topics. Each element in this list contains
- * the list of topics for the correponding item in
- * mAlternatives/mOriginalAlternatives
- */
- private List> mTopics;
-
- private Map mTopicMap;
- private Topic[] mAllTopics;
- private Topic[] mOriginalAllTopics;
-
- private Topic mOtherTopic;
- private Topic mSourceTopic;
-
- private TopicsAdapter mTopicsAdapter;
-
- public AlternativesAdapter(Context context, String authority, List alternatives) {
- mContext = context;
- mAuthority = authority;
- mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- mAlternatives = alternatives;
-
- boolean addOther = false;
- mTopics = new ArrayList>();
- mTopicMap = new TreeMap();
- for (Expr e : mAlternatives) {
- List topics = new ArrayList();
- for (Expr topicExpr : mTranslator.getTopicsOf(e)) {
- String name = mTranslator.linearizeSource(topicExpr);
- String key = name.toLowerCase();
- Topic topic = mTopicMap.get(key);
- if (topic == null) {
- topic = new Topic(name, topicExpr);
- mTopicMap.put(key,topic);
- }
- topics.add(topic);
- }
- mTopics.add(topics);
-
- if (topics.size() == 0)
- addOther = true;
- }
-
- int i = 0;
- mAllTopics = new Topic[mTopicMap.size() + (addOther ? 1 : 0)];
- for (Map.Entry entry : mTopicMap.entrySet()) {
- mAllTopics[i++] = entry.getValue();
- }
- if (addOther) {
- Expr topicExpr = Expr.readExpr("other_A");
- String name = mTranslator.linearizeSource(topicExpr);
- mOtherTopic = new Topic(name, topicExpr);
- mAllTopics[i++] = mOtherTopic;
- }
-
- mOriginalAllTopics = mAllTopics;
-
- mTopicsAdapter = new TopicsAdapter();
- }
-
- public AlternativesAdapter(Context context, String authority) {
- mContext = context;
- mAuthority = authority;
- mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- mAlternatives = null;
-
- mTopics = null;
-
- int i = 0;
- mTopicMap = new TreeMap();
- for (Expr topicExpr : mTranslator.getTopicsOf(null)) {
- String name = mTranslator.linearizeSource(topicExpr);
- String key = name.toLowerCase();
- Topic topic = mTopicMap.get(key);
- if (topic == null) {
- topic = new Topic(name, topicExpr);
- mTopicMap.put(key,topic);
- }
- }
- mAllTopics = new Topic[mTopicMap.size()];
- for (Map.Entry entry : mTopicMap.entrySet()) {
- mAllTopics[i++] = entry.getValue();
- }
-
- mOriginalAllTopics = mAllTopics;
-
- mTopicsAdapter = new TopicsAdapter();
- }
-
- /**
- * Returns the context associated with this array adapter. The context is used
- * to create views from the resource passed to the constructor.
- *
- * @return The Context associated with this adapter.
- */
- public Context getContext() {
- return mContext;
- }
-
- public String getAuthority() {
- return mAuthority;
- }
-
- /**
- * {@inheritDoc}
- */
- public int getCount() {
- if (mAlternatives == null)
- return 0;
- else
- return mAlternatives.size();
- }
-
- /**
- * {@inheritDoc}
- */
- public Expr getItem(int position) {
- return mAlternatives.get(position);
- }
-
- /**
- * Returns the position of the specified item in the array.
- *
- * @param item The item to retrieve the position of.
- *
- * @return The position of the specified item.
- */
- public int getPosition(Expr item) {
- if (mAlternatives == null)
- return -1;
- else
- return mAlternatives.indexOf(item);
- }
-
- /**
- * {@inheritDoc}
- */
- public long getItemId(int position) {
- return position;
- }
-
- public View getView(int position, View convertView, ViewGroup parent) {
- final Expr expr = getItem(position);
-
- if (mAuthority.equals(Translator.WORDS)) {
- if (convertView == null) {
- convertView = mInflater.inflate(R.layout.lexical_item, null);
- }
-
- TextView descView = (TextView)
- convertView.findViewById(R.id.lexical_desc);
-
- String phrase = mTranslator.generateLexiconEntry(expr);
- descView.setText(phrase);
-
- convertView.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- if (expandedView == view)
- collapse();
- else if (expandedView == null)
- expandWord(view, expr);
- else {
- collapse();
- expandWord(view, expr);
- }
- }
- });
- } else if (mAuthority.equals(Translator.SENTENCES)) {
- if (convertView == null) {
- convertView = mInflater.inflate(R.layout.alternative_item, null);
-
- View treeView = (View) convertView.findViewById(R.id.desc_details);
- ((RelativeLayout) convertView).removeView(treeView);
-
- TextView textView = (TextView) convertView.findViewById(R.id.abstract_tree);
- ((RelativeLayout) convertView).removeView(textView);
- }
-
- TextView descView = (TextView)
- convertView.findViewById(R.id.alternative_desc);
-
- String phrase = mTranslator.linearize(expr);
-
- // parse by words, marked by %, darkest red color
- if (phrase.charAt(0) == '%') {
- descView.setBackgroundDrawable(getResources().getDrawable(R.drawable.second_person_worst_utterance_bg));
- phrase = phrase.substring(2);
- }
-
- // parse by chunks, marked by *, red color
- else if (phrase.charAt(0) == '*') {
- descView.setBackgroundDrawable(getResources().getDrawable(R.drawable.second_person_chunk_utterance_bg));
- phrase = phrase.substring(2);
- }
-
- // parse error or unknown translations (in []) present, darkest red color
- else if (phrase.contains("parse error:") || phrase.contains("[")) {
- descView.setBackgroundDrawable(getResources().getDrawable(R.drawable.second_person_worst_utterance_bg));
- }
-
- // parse by domain grammar, marked by +, green color
- else if (phrase.charAt(0) == '+') {
- descView.setBackgroundDrawable(getResources().getDrawable(R.drawable.second_person_best_utterance_bg));
- phrase = phrase.substring(2);
- }
-
- else {
- descView.setBackgroundDrawable(getResources().getDrawable(R.drawable.second_person_utterance_bg));
- }
-
- descView.setText(phrase);
-
- convertView.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- if (expandedView == view)
- collapse();
- else if (expandedView == null)
- expandSentence(view, expr);
- else {
- collapse();
- expandSentence(view, expr);
- }
- }
- });
- }
-
- return convertView;
- }
-
- public boolean areAllItemsEnabled() {
- return true;
- }
-
- public boolean isEnabled(int position) {
- return true;
- }
-
- public TopicsAdapter getTopicsAdapter() {
- return mTopicsAdapter;
- }
-
- void filterOnTopics(List selected_topics) {
- if (mSourceTopic != null && !selected_topics.contains(mSourceTopic)) {
- mAlternatives = null;
- mOriginalAlternatives = null;
- mTopics = null;
- mAllTopics = mOriginalAllTopics;
- }
-
- if (mAlternatives == null) {
- if (selected_topics.size() == 0) {
- notifyDataSetChanged();
- return;
- }
-
- mSourceTopic = selected_topics.get(0);
- mAlternatives = mTranslator.getTopicWords(mSourceTopic.expr);
-
- mTopics = new ArrayList>();
- for (Expr e : mAlternatives) {
- List topics = new ArrayList();
- for (Expr topicExpr : mTranslator.getTopicsOf(e)) {
- String name = mTranslator.linearizeSource(topicExpr);
- String key = name.toLowerCase();
- topics.add(mTopicMap.get(key));
- }
- mTopics.add(topics);
- }
- }
-
- if (mOriginalAlternatives == null) {
- mOriginalAlternatives = new ArrayList(mAlternatives);
- }
-
- mAlternatives = new ArrayList();
- List> topics = new ArrayList>();
-
- for (Topic topic : mOriginalAllTopics) {
- topic.isAvailable = false;
- }
-
- int count = 0;
- for (int i = 0; i < mOriginalAlternatives.size(); i++) {
- boolean match = true;
- for (Topic topic : selected_topics) {
- if (topic == mOtherTopic) {
- if (mTopics.get(i).size() > 0) {
- match = false;
- break;
- }
- } else if (!mTopics.get(i).contains(topic)) {
- match = false;
- break;
- }
- }
- if (match) {
- mAlternatives.add(mOriginalAlternatives.get(i));
- if (mTopics.get(i).size() == 0) {
- if (!mOtherTopic.isAvailable)
- count++;
- mOtherTopic.isAvailable = true;
- } else {
- for (Topic topic : mTopics.get(i)) {
- if (!topic.isAvailable)
- count++;
- topic.isAvailable = true;
- }
- }
- }
- }
-
- int i = 0;
- mAllTopics = new Topic[count];
- for (Topic topic : mOriginalAllTopics) {
- if (topic.isAvailable)
- mAllTopics[i++] = topic;
- }
-
- notifyDataSetChanged();
- }
- }
-
- private class TopicsAdapter extends BaseAdapter implements ListAdapter {
- public TopicsAdapter() {
- }
-
- public Context getContext() {
- return mAdapter.getContext();
- }
-
- public int getCount() {
- return mAdapter.mAllTopics.length;
- }
-
- public Topic getItem(int position) {
- return mAdapter.mAllTopics[position];
- }
-
- public int getPosition(Topic topic) {
- for (int i = 0; i < mAdapter.mAllTopics.length; i++) {
- if (mAdapter.mAllTopics[i] == topic)
- return i;
- }
- return -1;
- }
-
- public long getItemId(int position) {
- return position;
- }
-
- // Shame on you Google this class should not have been here
- // but unfortuantely CheckBox.setChecked doesn't work and here
- // we need a workarround. Since the class is there now it is also
- // used to implement OnClickListener.
- private class TopicCheckBox extends CheckBox implements OnClickListener {
- private Topic mTopic;
-
- public TopicCheckBox(Context context, Topic topic) {
- super(context);
- mTopic = topic;
- setOnClickListener(this);
- }
-
- @Override
- public boolean isChecked() {
- if (mTopic == null)
- return false;
- else
- return mTopic.isChecked;
- }
-
- @Override
- public void onClick(View view) {
- mTopic.isChecked = !mTopic.isChecked;
- filterOnTopics();
- notifyDataSetChanged();
- }
- }
-
- private void filterOnTopics() {
- List selected_topics = new ArrayList();
- for (int i = 0; i < getCount(); i++) {
- Topic topic = getItem(i);
- if (topic.isChecked)
- selected_topics.add(topic);
- }
- mAdapter.filterOnTopics(selected_topics);
- }
-
- public View getView(int position, View convertView, ViewGroup parent) {
- Topic entry = getItem(position);
-
- CheckBox checkBox = new TopicCheckBox(getContext(), entry);
- checkBox.setText(entry.name);
- checkBox.setTextSize(25);
- checkBox.setTextColor(android.graphics.Color.parseColor("#808080"));
- return checkBox;
- }
- }
-
- @Override
- protected void onPostCreate(Bundle savedInstanceState) {
- super.onPostCreate(savedInstanceState);
- // Sync the toggle state after onRestoreInstanceState has occurred.
- mDrawerToggle.syncState();
- }
-
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- mDrawerToggle.onConfigurationChanged(newConfig);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Pass the event to ActionBarDrawerToggle, if it returns
- // true, then it has handled the app icon touch event
- if (mDrawerToggle.onOptionsItemSelected(item)) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/CompletionsView.java b/src/ui/android/src/org/grammaticalframework/ui/android/CompletionsView.java
deleted file mode 100644
index c59dbfe86..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/CompletionsView.java
+++ /dev/null
@@ -1,291 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
-import android.view.GestureDetector;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.inputmethod.CompletionInfo;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class CompletionsView extends View {
-
- private static final int OUT_OF_BOUNDS = -1;
-
- private TranslatorInputMethodService mService;
- private CompletionInfo[] mSuggestions;
- private int mSelectedIndex;
- private int mTouchX = OUT_OF_BOUNDS;
- private Drawable mSelectionHighlight;
- private boolean mTypedWordValid;
-
- private Rect mBgPadding;
-
- private static final int MAX_SUGGESTIONS = 32;
- private static final int SCROLL_PIXELS = 20;
-
- private int[] mWordWidth = new int[MAX_SUGGESTIONS];
- private int[] mWordX = new int[MAX_SUGGESTIONS];
-
- private static final int X_GAP = 10;
-
- private int mColorNormal;
- private int mColorRecommended;
- private int mColorOther;
- private int mVerticalPadding;
- private Paint mPaint;
- private boolean mScrolled;
- private int mTargetScrollX;
-
- private int mTotalWidth;
-
- private GestureDetector mGestureDetector;
-
- /**
- * Construct a CandidateView for showing suggested words for completion.
- * @param context
- * @param attrs
- */
- public CompletionsView(Context context) {
- super(context);
- mSelectionHighlight = context.getResources().getDrawable(
- android.R.drawable.list_selector_background);
- mSelectionHighlight.setState(new int[] {
- android.R.attr.state_enabled,
- android.R.attr.state_focused,
- android.R.attr.state_window_focused,
- android.R.attr.state_pressed
- });
-
- Resources r = context.getResources();
-
- setBackgroundColor(r.getColor(R.color.candidate_background));
-
- mColorNormal = r.getColor(R.color.candidate_normal);
- mColorRecommended = r.getColor(R.color.candidate_recommended);
- mColorOther = r.getColor(R.color.candidate_other);
- mVerticalPadding = r.getDimensionPixelSize(R.dimen.candidate_vertical_padding);
-
- mPaint = new Paint();
- mPaint.setColor(mColorNormal);
- mPaint.setAntiAlias(true);
- mPaint.setTextSize(r.getDimensionPixelSize(R.dimen.candidate_font_height));
- mPaint.setStrokeWidth(0);
-
- mGestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
- @Override
- public boolean onScroll(MotionEvent e1, MotionEvent e2,
- float distanceX, float distanceY) {
- mScrolled = true;
- int sx = getScrollX();
- sx += distanceX;
- if (sx < 0) {
- sx = 0;
- }
- if (sx + getWidth() > mTotalWidth) {
- sx -= distanceX;
- }
- mTargetScrollX = sx;
- scrollTo(sx, getScrollY());
- invalidate();
- return true;
- }
- });
- setHorizontalFadingEdgeEnabled(true);
- setWillNotDraw(false);
- setHorizontalScrollBarEnabled(false);
- setVerticalScrollBarEnabled(false);
- }
-
- /**
- * A connection back to the service to communicate with the text field
- * @param listener
- */
- public void setService(TranslatorInputMethodService listener) {
- mService = listener;
- }
-
- @Override
- public int computeHorizontalScrollRange() {
- return mTotalWidth;
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int measuredWidth = resolveSize(50, widthMeasureSpec);
-
- // Get the desired height of the icon menu view (last row of items does
- // not have a divider below)
- Rect padding = new Rect();
- mSelectionHighlight.getPadding(padding);
- final int desiredHeight = ((int)mPaint.getTextSize()) + mVerticalPadding
- + padding.top + padding.bottom;
-
- // Maximum possible width and desired height
- setMeasuredDimension(measuredWidth,
- resolveSize(desiredHeight, heightMeasureSpec));
- }
-
- /**
- * If the canvas is null, then only touch calculations are performed to pick the target
- * candidate.
- */
- @Override
- protected void onDraw(Canvas canvas) {
- if (canvas != null) {
- super.onDraw(canvas);
- }
- mTotalWidth = 0;
- if (mSuggestions == null) return;
-
- if (mBgPadding == null) {
- mBgPadding = new Rect(0, 0, 0, 0);
- if (getBackground() != null) {
- getBackground().getPadding(mBgPadding);
- }
- }
- int x = 0;
- final int count = mSuggestions.length;
- final int height = getHeight();
- final Rect bgPadding = mBgPadding;
- final Paint paint = mPaint;
- final int touchX = mTouchX;
- final int scrollX = getScrollX();
- final boolean scrolled = mScrolled;
- final boolean typedWordValid = mTypedWordValid;
- final int y = (int) (((height - mPaint.getTextSize()) / 2) - mPaint.ascent());
-
- for (int i = 0; i < count; i++) {
- String suggestion = mSuggestions[i].getText().toString();
- float textWidth = paint.measureText(suggestion);
- final int wordWidth = (int) textWidth + X_GAP * 2;
-
- mWordX[i] = x;
- mWordWidth[i] = wordWidth;
- paint.setColor(mColorNormal);
- if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled) {
- if (canvas != null) {
- canvas.translate(x, 0);
- mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height);
- mSelectionHighlight.draw(canvas);
- canvas.translate(-x, 0);
- }
- mSelectedIndex = i;
- }
-
- if (canvas != null) {
- if ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid)) {
- paint.setFakeBoldText(true);
- paint.setColor(mColorRecommended);
- } else if (i != 0) {
- paint.setColor(mColorOther);
- }
- canvas.drawText(suggestion, x + X_GAP, y, paint);
- paint.setColor(mColorOther);
- canvas.drawLine(x + wordWidth + 0.5f, bgPadding.top,
- x + wordWidth + 0.5f, height + 1, paint);
- paint.setFakeBoldText(false);
- }
- x += wordWidth;
- }
- mTotalWidth = x;
- if (mTargetScrollX != getScrollX()) {
- scrollToTarget();
- }
- }
-
- private void scrollToTarget() {
- int sx = getScrollX();
- if (mTargetScrollX > sx) {
- sx += SCROLL_PIXELS;
- if (sx >= mTargetScrollX) {
- sx = mTargetScrollX;
- requestLayout();
- }
- } else {
- sx -= SCROLL_PIXELS;
- if (sx <= mTargetScrollX) {
- sx = mTargetScrollX;
- requestLayout();
- }
- }
- scrollTo(sx, getScrollY());
- invalidate();
- }
-
- @SuppressLint("WrongCall")
- public void setSuggestions(CompletionInfo[] suggestions, boolean completions,
- boolean typedWordValid) {
- clear();
- if (suggestions != null) {
- mSuggestions = suggestions;
- }
- mTypedWordValid = typedWordValid;
- scrollTo(0, 0);
- mTargetScrollX = 0;
- // Compute the total width
- onDraw(null);
- invalidate();
- requestLayout();
- }
-
- public void clear() {
- mSuggestions = new CompletionInfo[0];
- mTouchX = OUT_OF_BOUNDS;
- mSelectedIndex = -1;
- invalidate();
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent me) {
-
- if (mGestureDetector.onTouchEvent(me)) {
- return true;
- }
-
- int action = me.getAction();
- int x = (int) me.getX();
- int y = (int) me.getY();
- mTouchX = x;
-
- switch (action) {
- case MotionEvent.ACTION_DOWN:
- mScrolled = false;
- invalidate();
- break;
- case MotionEvent.ACTION_MOVE:
- if (y <= 0) {
- // Fling up!?
- if (mSelectedIndex >= 0) {
- mService.pickSuggestionManually(mSelectedIndex);
- mSelectedIndex = -1;
- }
- }
- invalidate();
- break;
- case MotionEvent.ACTION_UP:
- if (!mScrolled) {
- if (mSelectedIndex >= 0) {
- mService.pickSuggestionManually(mSelectedIndex);
- }
- }
- mSelectedIndex = -1;
- removeHighlight();
- requestLayout();
- break;
- }
- return true;
- }
-
- private void removeHighlight() {
- mTouchX = OUT_OF_BOUNDS;
- invalidate();
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/ConversationView.java b/src/ui/android/src/org/grammaticalframework/ui/android/ConversationView.java
deleted file mode 100644
index b7d118e7c..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/ConversationView.java
+++ /dev/null
@@ -1,242 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import java.io.Serializable;
-import java.util.*;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.util.AttributeSet;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputMethodManager;
-import android.view.KeyEvent;
-import android.widget.EditText;
-import android.widget.ScrollView;
-import android.widget.TextView;
-import android.widget.TextView.OnEditorActionListener;
-
-import org.grammaticalframework.pgf.Expr;
-
-public class ConversationView extends ScrollView {
-
- private LayoutInflater mInflater;
-
- private ViewGroup mContent;
-
- private OnClickListener mAlternativesListener;
- private ASR.Listener mSpeechListener;
-
- public ConversationView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
-
- public ConversationView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public ConversationView(Context context) {
- super(context);
- }
-
- @Override
- protected void onFinishInflate() {
- super.onFinishInflate();
- mContent = (ViewGroup) findViewById(R.id.conversation_content);
- mInflater = LayoutInflater.from(getContext());
- }
-
- private class EditorListener implements OnEditorActionListener, OnClickListener {
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- if ((actionId & EditorInfo.IME_MASK_ACTION) != 0) {
- CharSequence text = v.getText();
- InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- if (inputMethodManager != null) {
- inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
- }
- v.setFocusable(false);
- mLastUtterance = v;
- if (mSpeechListener != null)
- mSpeechListener.onSpeechInput(text.toString().trim());
- return true;
- }
- return false;
- }
-
- @Override
- public void onClick(View v) {
- v.setFocusableInTouchMode(true);
- v.requestFocus();
- InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
- }
- };
-
- private EditorListener mEditorListener = new EditorListener();
- private TextView mLastUtterance = null;
-
- public void addFirstPersonUtterance(CharSequence text, boolean focused) {
- EditText edittext = (EditText)
- mInflater.inflate(R.layout.first_person_utterance, mContent, false);
- edittext.setText(text);
- edittext.setOnEditorActionListener(mEditorListener);
- edittext.setOnClickListener(mEditorListener);
- edittext.setHorizontallyScrolling(false);
- edittext.setMaxLines(Integer.MAX_VALUE);
- Bundle extras = edittext.getInputExtras(true);
- extras.putBoolean("show_language_toggle", false);
- mContent.addView(edittext);
-
- if (focused) {
- edittext.requestFocus();
- InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.showSoftInput(edittext, InputMethodManager.SHOW_IMPLICIT);
- } else {
- edittext.setFocusable(false);
- }
-
- post(new Runnable() {
- public void run() {
- fullScroll(FOCUS_DOWN);
- }
- });
-
- mLastUtterance = edittext;
- }
-
- @SuppressWarnings("deprecation")
- public CharSequence addSecondPersonUtterance(String authority, CharSequence source, CharSequence target, List alternatives) {
- TextView view;
- if (mLastUtterance != null && mLastUtterance.getTag() != null)
- view = (TextView) mLastUtterance.getTag();
- else {
- view = (TextView)
- mInflater.inflate(R.layout.second_person_utterance, mContent, false);
- if (mAlternativesListener != null)
- view.setOnClickListener(mAlternativesListener);
- mContent.addView(view);
- post(new Runnable() {
- public void run() {
- fullScroll(FOCUS_DOWN);
- }
- });
-
- mLastUtterance.setTag(view);
- }
-
- view.setTag(R.string.authority_key, authority);
- view.setTag(R.string.source_key, source);
- view.setTag(R.string.target_key, target);
- view.setTag(R.string.alternatives_key, alternatives);
-
- // parse by words, marked by %, darkest red color
- if (target.charAt(0) == '%') {
- view.setBackgroundDrawable(getResources().getDrawable(R.drawable.second_person_worst_utterance_bg));
- target = target.subSequence(1, target.length()).toString().trim();
- }
-
- // parse by chunks, marked by *, red color
- else if (target.charAt(0) == '*') {
- view.setBackgroundDrawable(getResources().getDrawable(R.drawable.second_person_chunk_utterance_bg));
- target = target.subSequence(1, target.length()).toString().trim();
- }
-
- // parse error: darkest red color
- else if (target.toString().contains("parse error:")) {
- view.setBackgroundDrawable(getResources().getDrawable(R.drawable.second_person_worst_utterance_bg));
- }
-
- // unknown linearizations in output: darkest red color. But replace [ ] by spaces and remove _ for better speech synthesis
- else if (target.toString().contains("[")) {
- view.setBackgroundDrawable(getResources().getDrawable(R.drawable.second_person_worst_utterance_bg));
- }
-
- // parse by domain grammar, marked by +, green color
- else if (target.charAt(0) == '+') {
- view.setBackgroundDrawable(getResources().getDrawable(R.drawable.second_person_best_utterance_bg));
- target = target.subSequence(1, target.length()).toString().trim();
- }
-
- else {
- view.setBackgroundDrawable(getResources().getDrawable(R.drawable.second_person_utterance_bg));
- }
-
- view.setText(target);
- return target;
- }
-
- public void updateLastUtterance(CharSequence text) {
- if (mLastUtterance != null)
- mLastUtterance.setText(text);
- }
-
- public void setOnAlternativesListener(final OnAlternativesListener listener) {
- if (listener == null)
- mAlternativesListener = null;
- else
- mAlternativesListener = new OnClickListener() {
- @Override
- public void onClick(View v) {
- String authority = v.getTag(R.string.authority_key).toString();
- String source = v.getTag(R.string.source_key).toString();
- List alternatives = (List) v.getTag(R.string.alternatives_key);
- listener.onAlternativesSelected(authority, source, alternatives);
- }
- };
- }
-
- public void setSpeechInputListener(ASR.Listener listener) {
- mSpeechListener = listener;
- }
-
- public interface OnAlternativesListener {
- public void onAlternativesSelected(CharSequence authority, CharSequence word, List althernatives);
- }
-
- public void saveConversation(Bundle state) {
- ArrayList authorities = new ArrayList();
- ArrayList firstPersonUtterances = new ArrayList();
- ArrayList secondPersonUtterances = new ArrayList();
- ArrayList translationAlternatives = new ArrayList();
-
- int childCount = mContent.getChildCount();
- for (int i = 0; i < childCount; i++) {
- View child = mContent.getChildAt(i);
- if (child.getClass() == TextView.class) {
- authorities.add(child.getTag(R.string.authority_key).toString());
- firstPersonUtterances.add(child.getTag(R.string.source_key).toString());
- secondPersonUtterances.add(child.getTag(R.string.target_key).toString());
- translationAlternatives.add(child.getTag(R.string.alternatives_key));
- }
- }
-
- state.putStringArrayList("authorities", authorities);
- state.putStringArrayList("first_person_uterances", firstPersonUtterances);
- state.putStringArrayList("second_person_uterances", secondPersonUtterances);
- state.putSerializable("translation_alternatives",(Serializable) translationAlternatives);
- }
-
- public void restoreConversation(Bundle state) {
- ArrayList authorities = state.getStringArrayList("authorities");
- ArrayList firstPersonUtterances = state.getStringArrayList("first_person_uterances");
- ArrayList secondPersonUtterances = state.getStringArrayList("second_person_uterances");
- ArrayList> translationAlternatives= (ArrayList>) state.getSerializable("translation_alternatives");
-
- int i = 0;
- while (i < authorities.size() &&
- i < firstPersonUtterances.size() &&
- i < Math.min(secondPersonUtterances.size(), translationAlternatives.size())) {
- String text = firstPersonUtterances.get(i);
- addFirstPersonUtterance(text, false);
-
- String authority = authorities.get(i);
- String translation = secondPersonUtterances.get(i);
- List alternatives = translationAlternatives.get(i);
- addSecondPersonUtterance(authority, text, translation, alternatives);
-
- i++;
- }
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/GFTranslator.java b/src/ui/android/src/org/grammaticalframework/ui/android/GFTranslator.java
deleted file mode 100644
index 8900b2415..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/GFTranslator.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-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;
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/HelpActivity.java b/src/ui/android/src/org/grammaticalframework/ui/android/HelpActivity.java
deleted file mode 100644
index c6a822484..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/HelpActivity.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.webkit.WebView;
-
-public class HelpActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_help);
- WebView wv = (WebView) findViewById(R.id.help_content);
- wv.loadUrl("file:///android_asset/help_content.html");
- }
-}
\ No newline at end of file
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/Language.java b/src/ui/android/src/org/grammaticalframework/ui/android/Language.java
deleted file mode 100644
index 000206045..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/Language.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import java.io.Serializable;
-
-public class Language implements Serializable {
- private static final long serialVersionUID = 1L;
-
- private final String mLangCode;
- private final String mLangName;
- private final String mConcrete;
- private final int mKeyboardPage1Resource;
- private final int mKeyboardPage2Resource;
-
- public Language(String langCode, String langName, String concrete,
- int keyboardResource) {
- mLangCode = langCode;
- mLangName = langName;
- mConcrete = concrete;
- mKeyboardPage1Resource = keyboardResource;
- mKeyboardPage2Resource = keyboardResource;
- }
-
- public Language(String langCode, String langName, String concrete,
- int keyboardPage1Resource, int keyboardPage2Resource) {
- mLangCode = langCode;
- mLangName = langName;
- mConcrete = concrete;
- mKeyboardPage1Resource = keyboardPage1Resource;
- mKeyboardPage2Resource = keyboardPage2Resource;
- }
-
- public String getLangCode() {
- return mLangCode;
- }
-
- public String getLangName() {
- return mLangName;
- }
-
- public int getKeyboardPage1Resource() {
- return mKeyboardPage1Resource;
- }
-
- public int getKeyboardPage2Resource() {
- return mKeyboardPage2Resource;
- }
-
- String getConcrete() {
- return mConcrete;
- }
-
- @Override
- public String toString() {
- return getLangName();
- }
-
- @Override
- public boolean equals(Object o) {
- Language other = (Language) o;
- return mLangCode.equals(other.mLangCode);
- }
-}
\ No newline at end of file
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/LanguageSelector.java b/src/ui/android/src/org/grammaticalframework/ui/android/LanguageSelector.java
deleted file mode 100644
index de628b2b5..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/LanguageSelector.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.View;
-import android.widget.AdapterView;
-import android.widget.Spinner;
-
-import java.util.List;
-
-public class LanguageSelector extends Spinner {
-
- public LanguageSelector(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
-
- public LanguageSelector(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public LanguageSelector(Context context) {
- super(context);
- }
-
- public void setLanguages(List languages) {
- setAdapter(new LanguagesAdapter(getContext(), languages));
- }
-
- public void setSelectedLanguage(Language selected) {
- setSelection(((LanguagesAdapter) getAdapter()).getPosition(selected));
- }
-
- public Language getSelectedLanguage() {
- return (Language) getSelectedItem();
- }
-
- public void setOnLanguageSelectedListener(final OnLanguageSelectedListener listener) {
- setOnItemSelectedListener(new OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView> parent, View view, int position, long id) {
- if (listener != null) {
- listener.onLanguageSelected((Language) parent.getItemAtPosition(position));
- }
- }
- @Override
- public void onNothingSelected(AdapterView> parent) {
- }
- });
- }
-
- public interface OnLanguageSelectedListener {
- void onLanguageSelected(Language language);
- }
-
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/LanguagesAdapter.java b/src/ui/android/src/org/grammaticalframework/ui/android/LanguagesAdapter.java
deleted file mode 100644
index e39ed7bd9..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/LanguagesAdapter.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import android.content.Context;
-import android.widget.ArrayAdapter;
-import android.widget.SpinnerAdapter;
-
-
-import java.util.List;
-
-public class LanguagesAdapter extends ArrayAdapter implements SpinnerAdapter {
-
- public LanguagesAdapter(Context context, List objects) {
- super(context, R.layout.languages_item, objects);
- }
-
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/LexiconSuggestionProvider.java b/src/ui/android/src/org/grammaticalframework/ui/android/LexiconSuggestionProvider.java
deleted file mode 100644
index 7b9813b7d..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/LexiconSuggestionProvider.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import android.content.ContentProvider;
-import android.content.ContentValues;
-import android.provider.BaseColumns;
-import android.database.Cursor;
-import android.database.MatrixCursor;
-import android.app.SearchManager;
-import android.net.Uri;
-import android.util.Log;
-import android.view.inputmethod.CompletionInfo;
-
-public class LexiconSuggestionProvider extends ContentProvider {
- private Translator mTranslator;
-
- public boolean onCreate() {
- return true;
- }
-
- public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
- mTranslator = ((GFTranslator) getContext().getApplicationContext()).getTranslator();
- String[] columns = new String[] {
- BaseColumns._ID,
- SearchManager.SUGGEST_COLUMN_TEXT_1,
- SearchManager.SUGGEST_COLUMN_QUERY
- };
-
- String query = uri.getLastPathSegment();
- MatrixCursor cursor = new MatrixCursor(columns, 100);
- for (CompletionInfo info : mTranslator.lookupWordPrefix(query)) {
- cursor.addRow(new String[] {Long.toString(info.getId()),info.getText().toString(),info.getText().toString()});
- }
-
- return cursor;
- }
-
- public Uri insert (Uri uri, ContentValues values) {
- throw new UnsupportedOperationException();
- }
-
- public int update (Uri uri, ContentValues values, String selection, String[] selectionArgs) {
- throw new UnsupportedOperationException();
- }
-
- public int delete (Uri uri, String selection, String[] selectionArgs) {
- throw new UnsupportedOperationException();
- }
-
- public String getType (Uri uri) {
- return null;
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/LocaleUtils.java b/src/ui/android/src/org/grammaticalframework/ui/android/LocaleUtils.java
deleted file mode 100644
index 9fb048908..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/LocaleUtils.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import android.text.TextUtils;
-
-import java.util.Locale;
-
-/**
- * Collections of utils to handle locales.
- */
-public class LocaleUtils {
-
- /**
- * Parses a locale string formatted by {@link Locale#toString()}.
- *
- * @return the parsed {@code Locale} or {@code defaultLocale} if the input was null or empty.
- */
- public static Locale parseJavaLocale(String localeString, Locale defaultLocale) {
- if (TextUtils.isEmpty(localeString)) {
- return defaultLocale;
- }
- final char separator = '_';
- int pos1 = localeString.indexOf(separator);
- if (pos1 == -1) {
- return new Locale(localeString);
- }
- String language = localeString.substring(0, pos1);
-
- int start2 = pos1 + 1;
- int pos2 = localeString.indexOf(separator, start2);
- if (pos2 == -1) {
- return new Locale(language, localeString.substring(start2));
- }
- String country = localeString.substring(start2, pos2);
-
- int start3 = pos2 + 1;
- int pos3 = localeString.indexOf(separator, start3);
- String variant = (pos3 == -1)
- ? localeString.substring(start3)
- : localeString.substring(start3, pos3);
- return new Locale(language, country, variant);
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/MainActivity.java b/src/ui/android/src/org/grammaticalframework/ui/android/MainActivity.java
deleted file mode 100644
index 369e542e9..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/MainActivity.java
+++ /dev/null
@@ -1,377 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import java.io.*;
-import java.util.*;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.speech.SpeechRecognizer;
-import android.net.Uri;
-import android.util.Log;
-import android.util.Pair;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.View.OnTouchListener;
-import android.widget.ImageView;
-
-import org.grammaticalframework.ui.android.ASR.State;
-import org.grammaticalframework.ui.android.LanguageSelector.OnLanguageSelectedListener;
-import org.grammaticalframework.ui.android.ConversationView.OnAlternativesListener;
-import org.grammaticalframework.pgf.*;
-
-public class MainActivity extends Activity {
-
- private static final boolean DBG = true;
- private static final String TAG = "MainActivity";
-
- private ImageView mStartStopButton;
-
- private ConversationView mConversationView;
-
- private LanguageSelector mSourceLanguageView;
-
- private LanguageSelector mTargetLanguageView;
-
- private ImageView mSwitchLanguagesButton;
-
- private ASR mAsr;
-
- private TTS mTts;
-
- private Translator mTranslator;
-
- private boolean input_mode;
-
- private SpeechInputListener mSpeechListener;
-
- private View mProgressBarView = null;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- mStartStopButton = (ImageView) findViewById(R.id.start_stop);
- mConversationView = (ConversationView) findViewById(R.id.conversation);
- mSourceLanguageView = (LanguageSelector) findViewById(R.id.source_language);
- mTargetLanguageView = (LanguageSelector) findViewById(R.id.target_language);
- mSwitchLanguagesButton = (ImageView) findViewById(R.id.switch_languages);
- mProgressBarView = findViewById(R.id.progressBarView);
-
- mStartStopButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- if (mAsr.isRunning()) {
- stopRecognition();
- } else {
- startRecognition();
- }
- }
- });
-
- SharedPreferences pref = getPreferences(MODE_PRIVATE);
- input_mode = pref.getBoolean("input_mode", true);
- if (!SpeechRecognizer.isRecognitionAvailable(this)) {
- input_mode = false;
- }
- mStartStopButton.setImageResource(input_mode ? R.drawable.ic_mic : R.drawable.ic_keyboard);
-
- mSpeechListener = new SpeechInputListener();
-
- mConversationView.setOnAlternativesListener(new OnAlternativesListener() {
- @Override
- public void onAlternativesSelected(CharSequence authority, CharSequence input, List alternatives) {
- Uri.Builder builder = new Uri.Builder();
- builder.scheme("gf-translator");
- builder.authority(authority.toString());
- builder.appendQueryParameter("source", input.toString());
- for (Expr e : alternatives) {
- builder.appendQueryParameter("alternative", e.toString());
- }
-
- Intent myIntent = new Intent(Intent.ACTION_VIEW, builder.build());
- MainActivity.this.startActivity(myIntent);
- }
- });
- mConversationView.setSpeechInputListener(mSpeechListener);
-
- mAsr = new ASR(this);
- mAsr.setListener(mSpeechListener);
-
- mTts = new TTS(this);
-
- mTranslator = ((GFTranslator) getApplicationContext()).getTranslator();
-
- mSourceLanguageView.setLanguages(mTranslator.getAvailableLanguages());
- mSourceLanguageView.setOnLanguageSelectedListener(new OnLanguageSelectedListener() {
- @Override
- public void onLanguageSelected(Language language) {
- onSourceLanguageSelected(language);
- }
- });
- mTargetLanguageView.setLanguages(mTranslator.getAvailableLanguages());
- mTargetLanguageView.setOnLanguageSelectedListener(new OnLanguageSelectedListener() {
- @Override
- public void onLanguageSelected(Language language) {
- onTargetLanguageSelected(language);
- }
- });
-
- mSwitchLanguagesButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- onSwitchLanguages();
- }
- });
-
- if (savedInstanceState != null) {
- mConversationView.restoreConversation(savedInstanceState);
- }
- }
-
- @Override
- protected void onResume() {
- super.onResume();
-
- mSourceLanguageView.setSelectedLanguage(mTranslator.getSourceLanguage());
- mTargetLanguageView.setSelectedLanguage(mTranslator.getTargetLanguage());
- }
-
- private void showProgressBar() {
- mProgressBarView.setVisibility(View.VISIBLE);
- }
-
- private void hideProgressBar() {
- mProgressBarView.setVisibility(View.GONE);
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mConversationView.saveConversation(outState);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.main, menu);
-
- menu.getItem(0).setTitle(input_mode ? R.string.keyboard_input : R.string.mic_input);
-
- if (!SpeechRecognizer.isRecognitionAvailable(this)) {
- menu.getItem(0).setEnabled(false);
- }
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle item selection
- switch (item.getItemId()) {
- case R.id.input_mode:
- if (input_mode) {
- item.setTitle(R.string.mic_input);
- mStartStopButton.setImageResource(R.drawable.ic_keyboard);
- input_mode = false;
- } else {
- item.setTitle(R.string.keyboard_input);
- mStartStopButton.setImageResource(R.drawable.ic_mic);
- input_mode = true;
- }
-
- SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
- editor.putBoolean("input_mode", input_mode);
- 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);
- return true;
- }
- case R.id.help: {
- Intent myIntent = new Intent(MainActivity.this, HelpActivity.class);
- MainActivity.this.startActivity(myIntent);
- return true;
- }
- default:
- return super.onOptionsItemSelected(item);
- }
- }
-
- @Override
- protected void onDestroy() {
- if (mAsr != null) {
- mAsr.destroy();
- mAsr = null;
- }
- if (mTts != null) {
- mTts.destroy();
- mTts = null;
- }
- super.onDestroy();
- }
-
- void onSourceLanguageSelected(Language language) {
- mTranslator.setSourceLanguage(language);
- if (TranslatorInputMethodService.getInstance() != null) {
- TranslatorInputMethodService.getInstance().handleChangeSourceLanguage(language);
- }
- }
-
- void onTargetLanguageSelected(Language language) {
- mTranslator.setTargetLanguage(language);
- if (TranslatorInputMethodService.getInstance() != null) {
- TranslatorInputMethodService.getInstance().handleChangeTargetLanguage(language);
- }
- }
-
- public String getSourceLanguageCode() {
- return mTranslator.getSourceLanguage().getLangCode();
- }
-
- public String getTargetLanguageCode() {
- return mTranslator.getTargetLanguage().getLangCode();
- }
-
- void onSwitchLanguages() {
- mTranslator.switchLanguages();
- mSourceLanguageView.setSelectedLanguage(mTranslator.getSourceLanguage());
- mTargetLanguageView.setSelectedLanguage(mTranslator.getTargetLanguage());
-
- if (TranslatorInputMethodService.getInstance() != null) {
- TranslatorInputMethodService.getInstance().handleSwitchLanguages();
- }
- }
-
- private void startRecognition() {
- if (input_mode) {
- mConversationView.addFirstPersonUtterance("...", false);
- mAsr.setLanguage(getSourceLanguageCode());
- mAsr.startRecognition();
- } else {
- mConversationView.addFirstPersonUtterance("", true);
- }
- }
-
- private void stopRecognition() {
- mAsr.stopRecognition();
- }
-
- private void handlePartialSpeechInput(String input) {
- mConversationView.updateLastUtterance(input);
- }
-
- private void handleSpeechInput(final String input) {
- final List list = mTranslator.lookupMorpho(input);
-
- mConversationView.updateLastUtterance(input);
- new AsyncTask>>() {
- @Override
- protected void onPreExecute() {
- showProgressBar();
- }
-
- @Override
- protected Pair> doInBackground(Void... params) {
- return mTranslator.translate(input);
- }
-
- @Override
- protected void onPostExecute(Pair> res) {
- String text = res.first;
- List transl = res.second;
-
- List alts = null;
- String authority = null;
-
- // filter out duplicates
- int i = 0;
- if (list.size() > 0) {
- alts = new ArrayList(list.size());
- authority = Translator.WORDS;
-
- while (i < list.size()) {
- MorphoAnalysis an = list.get(i);
- boolean found = false;
- for (int j = 0; j < i; j++) {
- if (list.get(j).getLemma().equals(an.getLemma())) {
- found = true;
- break;
- }
- }
-
- if (!found) {
- alts.add(Expr.readExpr(an.getLemma()));
- }
-
- i++;
- }
- } else {
- alts = new ArrayList(transl.size());
- authority = Translator.SENTENCES;
-
- Set strings = new HashSet();
- while (i < transl.size()) {
- String s = mTranslator.linearize(transl.get(i).getExpr());
- if (s.length() > 0 &&
- (s.charAt(0) == '%' || s.charAt(0) == '*' || s.charAt(0) == '+')) {
- s = s.substring(2);
- }
-
- if (!strings.contains(s)) {
- strings.add(s);
- alts.add(transl.get(i).getExpr());
- }
-
- i++;
- }
- }
-
- if (DBG) Log.d(TAG, "Speaking: " + res.first);
- CharSequence text2 =
- mConversationView.addSecondPersonUtterance(authority, input, text, alts);
- text2 = text2.toString().replace('[',' ').replace(']',' ').replaceAll("_","").trim();
- mTts.speak(getTargetLanguageCode(), text2.toString());
-
- hideProgressBar();
- }
- }.execute();
- }
-
- private class SpeechInputListener implements ASR.Listener {
-
- @Override
- public void onPartialInput(String input) {
- handlePartialSpeechInput(input);
- }
-
- @Override
- public void onSpeechInput(String input) {
- handleSpeechInput(input);
- }
-
- @Override
- public void onStateChanged(State newState) {
- if (newState == ASR.State.IDLE) {
- //clear the overlay
- mStartStopButton.getDrawable().clearColorFilter();
- } else {
- mStartStopButton.getDrawable().setColorFilter(0xffff0000,android.graphics.PorterDuff.Mode.SRC_ATOP);
- }
- mStartStopButton.invalidate();
- }
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/ParseTreeView.java b/src/ui/android/src/org/grammaticalframework/ui/android/ParseTreeView.java
deleted file mode 100644
index b2ff74183..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/ParseTreeView.java
+++ /dev/null
@@ -1,270 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-import android.graphics.Rect;
-import android.util.AttributeSet;
-import android.util.SparseArray;
-import android.view.MotionEvent;
-import android.view.View;
-
-import org.grammaticalframework.pgf.Bracket;
-
-
-public class ParseTreeView extends View {
- private static final float SISTER_SKIP = 25;
- private static final float PARENT_SKIP = 0.5f;
- private static final float ABOVE_LINE_SKIP = 0.1f;
- private static final float BELOW_LINE_SKIP = 0.1f;
-
- private Paint paint;
- private Object[] brackets;
-
- private float lastMotionX;
- private float scrollRange;
-
- public ParseTreeView(Context context) {
- this(context, null);
- }
-
- public ParseTreeView(Context context, AttributeSet attrs) {
- super(context, attrs, R.attr.parseTreeViewStyle);
-
- paint = new Paint();
- paint.setTextSize(60);
- brackets = null;
- scrollRange = 0;
- }
-
- public Object[] getBrackets() {
- return brackets;
- }
-
- public void setBrackets(Object[] brackets) {
- this.brackets = brackets;
- awakenScrollBars();
- }
-
- static class MeasureResult {
- float width = 0.0f;
- float height = 0.0f;
- float nodeTab = 0.0f;
- float nodeCenter = 0.0f;
- float childTab = 0.0f;
- float localWidth = 0.0f;
- float localHeight = 0.0f;
- }
-
- private MeasureResult mr = new MeasureResult();
- private SparseArray coords = new SparseArray();
- private PointF zeroPoint = new PointF();
-
- private void measureTree(Object o) {
- if (o instanceof Bracket) {
- Bracket bracket = (Bracket) o;
-
- Rect bounds = new Rect();
- paint.getTextBounds(bracket.cat,0,bracket.cat.length(),bounds);
- float localWidth = bounds.width();
- float localHeight = bounds.height();
- float layerHeight = localHeight * (1.0f + BELOW_LINE_SKIP + ABOVE_LINE_SKIP + PARENT_SKIP);
-
- PointF local = coords.get(bracket.fid);
- if (local == null) {
- coords.put(bracket.fid, zeroPoint);
- } else {
- localWidth = 0;
- }
-
- float subWidth = 0.0f;
- float subHeight = 0.0f;
- float nodeCenter = 0.0f;
- for (int i = 0; i < bracket.children.length; i++) {
- measureTree(bracket.children[i]);
-
- if (i == 0) {
- nodeCenter += (subWidth + mr.nodeCenter) / 2.0;
- }
- if (i == bracket.children.length - 1) {
- nodeCenter += (subWidth + mr.nodeCenter) / 2.0;
- }
-
- subWidth += mr.width;
- if (i < bracket.children.length - 1) {
- subWidth += SISTER_SKIP;
- }
-
- if (subHeight < mr.height)
- subHeight = mr.height;
- }
- float localLeft = localWidth / 2.0f;
- float subLeft = nodeCenter;
- float totalLeft = Math.max(localLeft, subLeft);
- float localRight = localWidth / 2.0f;
- float subRight = subWidth - nodeCenter;
- float totalRight = Math.max(localRight, subRight);
- mr.width = totalLeft + totalRight;
- mr.height = layerHeight + subHeight;
- mr.childTab = totalLeft - subLeft;
- mr.nodeTab = totalLeft - localLeft;
- mr.nodeCenter = nodeCenter + mr.childTab;
- mr.localWidth = localWidth;
- mr.localHeight = localHeight;
- } else {
- String word = o.toString();
-
- Rect bounds = new Rect();
- paint.getTextBounds(word,0,word.length(),bounds);
- mr.width = bounds.width();
- mr.height = bounds.height();
- mr.nodeTab = 0.0f;
- mr.nodeCenter = bounds.width() / 2.0f;
- mr.childTab = 0.0f;
- mr.localWidth = bounds.width();
- mr.localHeight = bounds.height();
- }
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- if (brackets == null) {
- setMeasuredDimension(0, 0);
- return;
- }
-
- coords.clear();
-
- float width = 0.0f;
- float height = 0.0f;
- for (int i = 0; i < brackets.length; i++) {
- measureTree(brackets[i]);
-
- width += mr.width;
- if (i < brackets.length - 1) {
- width += SISTER_SKIP;
- }
-
- if (height < mr.height)
- height = mr.height;
- }
-
- height += paint.getFontMetrics().descent;
-
- int w = getPaddingLeft() + (int) width + getPaddingRight();
- int h = getPaddingTop() + (int) height + getPaddingBottom();
-
- scrollRange = w;
-
- int widthReq = MeasureSpec.getSize(widthMeasureSpec);
- if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY ||
- (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.AT_MOST && w > widthReq)) {
- w = widthReq;
- }
- int heightReq = MeasureSpec.getSize(heightMeasureSpec);
- if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY ||
- (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST && h > heightReq)) {
- h = heightReq;
- }
-
- setMeasuredDimension(w, h);
- }
-
- private void drawTree(Canvas canvas,
- float x, float y, float bottom, PointF parentPoint,
- Object o) {
- if (o instanceof Bracket) {
- Bracket bracket = (Bracket) o;
-
- PointF lineStart = coords.get(bracket.fid);
- if (lineStart == null) {
- lineStart = new PointF(x + mr.nodeCenter, y + mr.localHeight * (1.0f + BELOW_LINE_SKIP));
- coords.put(bracket.fid, lineStart);
-
- if (parentPoint != null) {
- float lineEndX = x + mr.nodeCenter;
- float lineEndY = y;
- canvas.drawLine(parentPoint.x, parentPoint.y, lineEndX, lineEndY, paint);
- }
-
- canvas.drawText(bracket.cat, x+mr.nodeTab, y+mr.localHeight, paint);
- }
-
- float layerMultiplier = (1.0f + BELOW_LINE_SKIP + ABOVE_LINE_SKIP + PARENT_SKIP);
- float layerHeight = mr.localHeight * layerMultiplier;
- float childStartX = x + mr.childTab;
- float childStartY = y + layerHeight;
- for (int i = 0; i < bracket.children.length; i++) {
- Object child = bracket.children[i];
- SparseArray copy = coords.clone();
- measureTree(child);
- coords = copy;
- float w = mr.width;
- drawTree(canvas, childStartX, childStartY, bottom, lineStart, child);
- childStartX += w + SISTER_SKIP;
- }
- } else {
- float lineEndX = x + mr.nodeCenter;
- float lineEndY = bottom - mr.height;
- canvas.drawLine(parentPoint.x, parentPoint.y, lineEndX, lineEndY, paint);
- canvas.drawText(o.toString(), x, bottom, paint);
- }
- }
-
- @Override
- protected void onDraw (Canvas canvas) {
- super.onDraw(canvas);
-
- if (brackets == null) {
- return;
- }
-
- coords.clear();
-
- float startX = getPaddingLeft();
- for (int i = 0; i < brackets.length; i++) {
- Object child = brackets[i];
-
- SparseArray copy = coords.clone();
- measureTree(child);
- coords = copy;
- float w = mr.width;
- drawTree(canvas, startX, getPaddingTop(), getPaddingTop()+mr.height, null, child);
- startX += w + SISTER_SKIP;
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent ev) {
- switch (ev.getAction()) {
- case MotionEvent.ACTION_DOWN:
- // Remember where the motion event started
- lastMotionX = ev.getX();
- break;
- case MotionEvent.ACTION_MOVE:
- // Scroll to follow the motion event
- float x = ev.getX();
- final int deltaX = (int) (lastMotionX - x);
- lastMotionX = x;
- int offset = computeHorizontalScrollOffset() + deltaX;
- int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent();
- if (range > 0) {
- if (offset < 0)
- offset = 0;
- if (offset > range)
- offset = range;
- scrollTo(offset, 0);
- }
- break;
- case MotionEvent.ACTION_UP:
- break;
- }
- return true;
- }
-
- @Override
- protected int computeHorizontalScrollRange() {
- return (int) scrollRange;
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/RotationGestureDetector.java b/src/ui/android/src/org/grammaticalframework/ui/android/RotationGestureDetector.java
deleted file mode 100644
index d077db1bc..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/RotationGestureDetector.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import android.view.MotionEvent;
-
-public class RotationGestureDetector {
-
- private static final int INVALID_POINTER_ID = -1;
- private float fX, fY, sX, sY, focalX, focalY;
- private int ptrID1, ptrID2;
- private float mAngle;
- private boolean firstTouch;
-
- private OnRotationGestureListener mListener;
-
- public RotationGestureDetector(OnRotationGestureListener listener) {
- mListener = listener;
- ptrID1 = INVALID_POINTER_ID;
- ptrID2 = INVALID_POINTER_ID;
- }
-
- public float getAngle() {
- return mAngle;
- }
-
- public boolean onTouchEvent(MotionEvent event){
- switch (event.getActionMasked()) {
- case MotionEvent.ACTION_DOWN:
- sX = event.getX();
- sY = event.getY();
- ptrID1 = event.getPointerId(0);
- mAngle = 0;
- firstTouch = true;
- break;
- case MotionEvent.ACTION_POINTER_DOWN:
- fX = event.getX();
- fY = event.getY();
- focalX = getMidpoint(fX, sX);
- focalY = getMidpoint(fY, sY);
- ptrID2 = event.getPointerId(event.getActionIndex());
- mAngle = 0;
- firstTouch = true;
- break;
- case MotionEvent.ACTION_MOVE:
- if(ptrID1 != INVALID_POINTER_ID && ptrID2 != INVALID_POINTER_ID) {
- float nfX, nfY, nsX, nsY;
- nsX = event.getX(event.findPointerIndex(ptrID1));
- nsY = event.getY(event.findPointerIndex(ptrID1));
- nfX = event.getX(event.findPointerIndex(ptrID2));
- nfY = event.getY(event.findPointerIndex(ptrID2));
- if (firstTouch) {
- mAngle = 0;
- firstTouch = false;
- } else {
- mAngle = angleBetweenLines(fX, fY, sX, sY, nfX, nfY, nsX, nsY);
- }
-
- if (mListener != null) {
- mListener.OnRotation(this);
- }
- fX = nfX;
- fY = nfY;
- sX = nsX;
- sY = nsY;
- }
- break;
- case MotionEvent.ACTION_UP:
- ptrID1 = INVALID_POINTER_ID;
- break;
- case MotionEvent.ACTION_POINTER_UP:
- ptrID2 = INVALID_POINTER_ID;
- break;
- }
- return true;
- }
-
- private float getMidpoint(float a, float b) {
- return (a + b) / 2;
- }
-
- private float findAngleDelta(float angle1, float angle2)
- {
- angle2 = angle2 % 360.0f;
- angle1 = angle1 % 360.0f;
-
- float dist = angle1 - angle2;
- if (dist < -180.0f)
- {
- dist += 360.0f;
- }
- else if (dist > 180.0f)
- {
- dist -= 360.0f;
- }
-
- return dist;
- }
-
- private float angleBetweenLines(float fx1, float fy1, float fx2, float fy2, float sx1, float sy1, float sx2, float sy2)
- {
- float angle1 = (float) Math.atan2((fy1 - fy2), (fx1 - fx2));
- float angle2 = (float) Math.atan2((sy1 - sy2), (sx1 - sx2));
-
- return findAngleDelta((float)Math.toDegrees(angle1),(float)Math.toDegrees(angle2));
- }
-
- public static interface OnRotationGestureListener {
- public boolean OnRotation(RotationGestureDetector detector);
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/SemanticGraph.java b/src/ui/android/src/org/grammaticalframework/ui/android/SemanticGraph.java
deleted file mode 100644
index 0033404c9..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/SemanticGraph.java
+++ /dev/null
@@ -1,235 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import java.util.*;
-
-public class SemanticGraph {
- private Map nodes;
- private List edges;
-
- private float layoutMinX;
- private float layoutMaxX;
- private float layoutMinY;
- private float layoutMaxY;
-
- public SemanticGraph() {
- nodes = new HashMap();
- edges = new ArrayList();
-
- layoutMinX = 0;
- layoutMaxX = 0;
- layoutMinY = 0;
- layoutMaxY = 0;
- }
-
- public Node addNode(String lemma, List senses) {
- Node n = nodes.get(lemma);
- if (n == null) {
- n = new Node(lemma, senses);
- }
- nodes.put(lemma,n);
- return n;
- }
-
- public Node getNode(String lemma) {
- return nodes.get(lemma);
- }
-
- public Collection getNodes() {
- return Collections.unmodifiableCollection(nodes.values());
- }
-
- public Edge addEdge(Node node1, Node node2) {
- Edge edge = new Edge(node1, node2);
- edges.add(edge);
- return edge;
- }
-
- private static final int LAYOUT_ITERATIONS = 500;
- private static final float LAYOUT_K = 2;
- private static final float LAYOUT_C = 0.01f;
- private static final float LAYOUT_MAX_VERTEX_MOVEMENT = 0.5f;
- private static final float LAYOUT_MAX_REPULSIVE_FORCE_DISTANCE = 6;
-
- public void layout() {
- layoutPrepare();
- for (int i = 0; i < LAYOUT_ITERATIONS; i++) {
- layoutIteration();
- }
- layoutCalcBounds();
- }
-
- public float getLayoutMinX() {
- return layoutMinX;
- }
-
- public float getLayoutMaxX() {
- return layoutMaxX;
- }
-
- public float getLayoutMinY() {
- return layoutMinY;
- }
-
- public float getLayoutMaxY() {
- return layoutMaxY;
- }
-
- private void layoutPrepare() {
- for (Node node : nodes.values()) {
- node.layoutForceX = 0;
- node.layoutForceY = 0;
- }
- }
-
- private void layoutIteration() {
- List prev = new ArrayList();
- for(Node node1 : this.nodes.values()) {
- for (Node node2 : prev) {
- layoutRepulsive(node1, node2);
- }
- prev.add(node1);
- }
-
- // Forces on nodes due to edge attractions
- for (Edge edge : edges) {
- layoutAttractive(edge);
- }
-
- // Move by the given force
- for (Node node : nodes.values()) {
- float xmove = LAYOUT_C * node.layoutForceX;
- float ymove = LAYOUT_C * node.layoutForceY;
-
- float max = LAYOUT_MAX_VERTEX_MOVEMENT;
- if (xmove > max) xmove = max;
- if (xmove < -max) xmove = -max;
- if (ymove > max) ymove = max;
- if (ymove < -max) ymove = -max;
-
- node.layoutPosX += xmove;
- node.layoutPosY += ymove;
- node.layoutForceX = 0;
- node.layoutForceY = 0;
- }
- }
-
- private void layoutRepulsive(Node node1, Node node2) {
- float dx = node2.layoutPosX - node1.layoutPosX;
- float dy = node2.layoutPosY - node1.layoutPosY;
- float d2 = dx * dx + dy * dy;
- if (d2 < 0.01) {
- dx = (float) (0.1 * Math.random() + 0.1);
- dy = (float) (0.1 * Math.random() + 0.1);
- d2 = dx * dx + dy * dy;
- }
- float d = (float) Math.sqrt(d2);
- if (d < LAYOUT_MAX_REPULSIVE_FORCE_DISTANCE) {
- float repulsiveForce = LAYOUT_K * LAYOUT_K / d;
- node2.layoutForceX += repulsiveForce * dx / d;
- node2.layoutForceY += repulsiveForce * dy / d;
- node1.layoutForceX -= repulsiveForce * dx / d;
- node1.layoutForceY -= repulsiveForce * dy / d;
- }
- }
-
- private void layoutAttractive(Edge edge) {
- Node node1 = edge.source;
- Node node2 = edge.target;
-
- float dx = node2.layoutPosX - node1.layoutPosX;
- float dy = node2.layoutPosY - node1.layoutPosY;
- float d2 = dx * dx + dy * dy;
- if (d2 < 0.01) {
- dx = (float) (0.1 * Math.random() + 0.1);
- dy = (float) (0.1 * Math.random() + 0.1);
- d2 = dx * dx + dy * dy;
- }
- float d = (float) Math.sqrt(d2);
- if (d > LAYOUT_MAX_REPULSIVE_FORCE_DISTANCE) {
- d = LAYOUT_MAX_REPULSIVE_FORCE_DISTANCE;
- d2 = d * d;
- }
- float attractiveForce = (d2 - LAYOUT_K * LAYOUT_K) / LAYOUT_K;
- attractiveForce *= Math.log(edge.attraction) * 0.5 + 1;
-
- node2.layoutForceX -= attractiveForce * dx / d;
- node2.layoutForceY -= attractiveForce * dy / d;
- node1.layoutForceX += attractiveForce * dx / d;
- node1.layoutForceY += attractiveForce * dy / d;
- }
-
- private void layoutCalcBounds() {
- float minx = Float.POSITIVE_INFINITY,
- maxx = Float.NEGATIVE_INFINITY,
- miny = Float.POSITIVE_INFINITY,
- maxy = Float.NEGATIVE_INFINITY;
-
- for (Node node : nodes.values()) {
- float x = node.layoutPosX;
- float y = node.layoutPosY;
-
- if (x > maxx) maxx = x;
- if (x < minx) minx = x;
- if (y > maxy) maxy = y;
- if (y < miny) miny = y;
- }
-
- layoutMinX = minx;
- layoutMaxX = maxx;
- layoutMinY = miny;
- layoutMaxY = maxy;
- }
-
- public static class Node {
- private String lemma;
- private List senses;
-
- private float layoutPosX;
- private float layoutPosY;
- private float layoutForceX;
- private float layoutForceY;
-
-
- private Node(String lemma, List senses) {
- this.lemma = lemma;
- this.senses = senses;
-
- layoutPosX = 0;
- layoutPosY = 0;
- layoutForceX = 0;
- layoutForceY = 0;
- }
-
- public String getLemma() {
- return lemma;
- }
-
- public int getSenseCount() {
- return senses.size();
- }
-
- public Object getSenseId(int i) {
- return senses.get(i);
- }
-
- public float getLayoutX() {
- return layoutPosX;
- }
-
- public float getLayoutY() {
- return layoutPosY;
- }
- }
-
- public static class Edge {
- private Node source;
- private Node target;
- private float attraction;
-
- private Edge(Node source, Node target) {
- this.source = source;
- this.target = target;
- this.attraction = 1;
- }
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/SemanticGraphActivity.java b/src/ui/android/src/org/grammaticalframework/ui/android/SemanticGraphActivity.java
deleted file mode 100644
index 38878cc50..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/SemanticGraphActivity.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import java.util.*;
-
-import android.app.Activity;
-import android.app.SearchManager;
-import android.os.Bundle;
-import android.os.AsyncTask;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.ImageView;
-import android.widget.Toast;
-import android.content.Intent;
-
-import org.grammaticalframework.pgf.MorphoAnalysis;
-import org.grammaticalframework.ui.android.LanguageSelector.OnLanguageSelectedListener;
-
-public class SemanticGraphActivity extends Activity {
- private Translator mTranslator;
-
- private LanguageSelector mLanguageView;
- private View mProgressBarView = null;
- private ImageView mAddWordButton;
- private SemanticGraphView mGraphView;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_semantic_graph);
-
- mTranslator = ((GFTranslator) getApplicationContext()).getTranslator();
-
- mLanguageView = (LanguageSelector) findViewById(R.id.show_language);
- mLanguageView.setLanguages(mTranslator.getAvailableLanguages());
- mLanguageView.setOnLanguageSelectedListener(new OnLanguageSelectedListener() {
- @Override
- public void onLanguageSelected(final Language language) {
- new AsyncTask() {
- @Override
- protected void onPreExecute() {
- showProgressBar();
- }
-
- @Override
- protected Void doInBackground(Void... params) {
- mTranslator.setSourceLanguage(language);
- mTranslator.isTargetLanguageLoaded();
- return null;
- }
-
- @Override
- protected void onPostExecute(Void result) {
- hideProgressBar();
- }
- }.execute();
- }
- });
-
- mAddWordButton = (ImageView) findViewById(R.id.add_word);
-
- mGraphView = (SemanticGraphView) findViewById(R.id.semantic_graph);
-
- mAddWordButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- onSearchRequested();
- }
- });
-
- mProgressBarView = findViewById(R.id.progressBarView);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
-
- mLanguageView.setSelectedLanguage(mTranslator.getSourceLanguage());
- }
-
- private void showProgressBar() {
- mProgressBarView.setVisibility(View.VISIBLE);
- }
-
- private void hideProgressBar() {
- mProgressBarView.setVisibility(View.GONE);
- }
-
- @Override
- protected void onNewIntent (Intent intent) {
- if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
- String query = intent.getStringExtra(SearchManager.QUERY);
- List list = mTranslator.lookupMorpho(query);
- if (list == null || list.size() == 0) {
- Toast toast = Toast.makeText(this, "\""+query+"\" doesn't match", Toast.LENGTH_SHORT);
- toast.show();
- } else {
- mGraphView.getGraph().addNode(query, list);
- mGraphView.refresh();
- }
- }
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/SemanticGraphManager.java b/src/ui/android/src/org/grammaticalframework/ui/android/SemanticGraphManager.java
deleted file mode 100644
index f3b26a3cf..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/SemanticGraphManager.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import java.io.*;
-import android.content.Context;
-import android.util.Log;
-
-import org.grammaticalframework.sg.*;
-import org.grammaticalframework.pgf.*;
-
-public class SemanticGraphManager implements Closeable {
- private final Context mContext;
- private SG mDB;
-
- public static final String DATABASE_FILE_NAME = "semantics.db";
-
- public SemanticGraphManager(Context context) {
- mContext = context;
- mDB = null;
- }
-
- private void createDatabaseFromAssets() throws SGError, IOException {
- if (mDB != null)
- return;
-
- String path = mContext.getDatabasePath(DATABASE_FILE_NAME).getPath();
-
- boolean exists = false;
-
- File file = new File(path);
- if (((GFTranslator) mContext.getApplicationContext()).getTranslator().isUpgraded("db_version")) {
- file.delete();
- } else {
- if (file.exists()) {
- exists = true;
- }
- }
-
- File dir = new File(mContext.getApplicationInfo().dataDir + "/databases");
- if (!dir.exists()) {
- dir.mkdir();
- }
-
- if (!extractDatabase(file))
- return;
-
- mDB = SG.openSG(path);
- if (exists)
- return;
- }
-
- private boolean extractDatabase(File outFile) {
- InputStream in = null;
- OutputStream out = null;
- try {
- in = mContext.getAssets().open(DATABASE_FILE_NAME);
- out = new FileOutputStream(outFile);
- copyFile(in, out);
- return true;
- } catch(IOException e) {
- Log.e("tag", "Failed to copy asset file: " + DATABASE_FILE_NAME, e);
- }
- finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- // NOOP
- }
- }
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- // NOOP
- }
- }
- }
-
- return false;
- }
-
- private void copyFile(InputStream in, OutputStream out) throws IOException {
- byte[] buffer = new byte[1024];
- int read;
- while((read = in.read(buffer)) != -1){
- out.write(buffer, 0, read);
- }
- }
-
- public void close() {
- if (mDB != null) {
- mDB.close();
- mDB = null;
- }
- }
-
- public TripleResult queryTriple(Expr subj, Expr pred, Expr obj) throws IOException {
- createDatabaseFromAssets();
- return mDB.queryTriple(subj, pred, obj);
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/SemanticGraphView.java b/src/ui/android/src/org/grammaticalframework/ui/android/SemanticGraphView.java
deleted file mode 100644
index 81785d5ce..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/SemanticGraphView.java
+++ /dev/null
@@ -1,144 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import android.view.View;
-import android.view.GestureDetector;
-import android.view.ScaleGestureDetector;
-import android.view.MotionEvent;
-import android.graphics.Paint;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Rect;
-import android.content.Context;
-import android.util.AttributeSet;
-import android.util.Log;
-
-public class SemanticGraphView extends View implements GestureDetector.OnGestureListener, ScaleGestureDetector.OnScaleGestureListener, RotationGestureDetector.OnRotationGestureListener {
-
- private SemanticGraph mGraph = new SemanticGraph();
-
- private float mStartX = 0;
- private float mStartY = 0;
- private float mFocusX = 0;
- private float mFocusY = 0;
- private float mScale = 1;
- private float mAngle = 0;
-
- private Paint mPaint;
-
- private GestureDetector mGD;
- private ScaleGestureDetector mSGD;
- private RotationGestureDetector mRGD;
-
- private static final float TEXT_PAD = 10;
- private static final float SENSE_POINT_RADIUS = 5;
-
- public SemanticGraphView(Context context, AttributeSet attrs) {
- super(context, attrs);
-
- mPaint = new Paint();
- mPaint.setTextSize(60);
-
- mGD = new GestureDetector(this);
- mSGD = new ScaleGestureDetector(context,this);
- mRGD = new RotationGestureDetector(this);
- }
-
- public SemanticGraph getGraph() {
- return mGraph;
- }
-
- public void refresh() {
- mGraph.layout();
- invalidate();
- }
-
- @Override
- protected void onDraw (Canvas canvas) {
- super.onDraw(canvas);
-
- canvas.scale(mScale,mScale,mFocusX,mFocusY);
- canvas.translate(mStartX, mStartY);
- canvas.rotate(mAngle);
-
- Rect bounds = new Rect();
-
- float dx = mGraph.getLayoutMinX();
- float sx = getWidth()/(mGraph.getLayoutMaxX()-mGraph.getLayoutMinX());
- float dy = mGraph.getLayoutMinY();
- float sy = getHeight()/(mGraph.getLayoutMaxY()-mGraph.getLayoutMinY());
- for (SemanticGraph.Node node : mGraph.getNodes()) {
- mPaint.getTextBounds(node.getLemma().toCharArray(), 0, node.getLemma().length(), bounds);
-
- float left = (node.getLayoutX()-dx)*sx - TEXT_PAD;
- float base = (node.getLayoutY()-dy)*sy;
- float top = base - bounds.height() - TEXT_PAD;
- float right = left + bounds.right + TEXT_PAD;
- float bottom = base + bounds.bottom + TEXT_PAD;
- float sqrt2 = (float) Math.sqrt(2);
-
- canvas.drawText(node.getLemma(), left + TEXT_PAD, base, mPaint);
-
- float pi = (float) Math.PI;
- for (int i = 0; i < node.getSenseCount(); i++) {
- float phi = i * 2*pi / node.getSenseCount();
- float cx = ((left+right) + (right-left)*sqrt2*((float) Math.sin(phi)))/2;
- float cy = ((top+bottom) + (bottom-top)*sqrt2*((float) Math.cos(phi)))/2;
-
- canvas.drawCircle(cx,cy,SENSE_POINT_RADIUS,mPaint);
- }
- }
- }
-
- public boolean onTouchEvent(MotionEvent ev) {
- mGD.onTouchEvent(ev);
- mSGD.onTouchEvent(ev);
- mRGD.onTouchEvent(ev);
- return true;
- }
-
- public boolean onDown(MotionEvent e) {
- return true;
- }
-
- public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
- return true;
- }
-
- public void onLongPress(MotionEvent e) {
- }
-
- public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
- mStartX -= distanceX;
- mStartY -= distanceY;
- invalidate();
- return true;
- }
-
- public void onShowPress(MotionEvent e) {
- }
-
- public boolean onSingleTapUp(MotionEvent e) {
- return true;
- }
-
- public boolean onScaleBegin(ScaleGestureDetector detector) {
- return true;
- }
-
- public boolean onScale(ScaleGestureDetector detector) {
- mScale *= detector.getScaleFactor();
- mFocusX = detector.getFocusX();
- mFocusY = detector.getFocusY();
- invalidate();
- return true;
- }
-
- public void onScaleEnd(ScaleGestureDetector detector) {
- }
-
- public boolean OnRotation(RotationGestureDetector detector) {
- mAngle -= detector.getAngle();
- invalidate();
- return true;
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/TTS.java b/src/ui/android/src/org/grammaticalframework/ui/android/TTS.java
deleted file mode 100644
index 3e020f0af..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/TTS.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import android.content.Context;
-import android.media.AudioManager;
-import android.speech.tts.TextToSpeech;
-import android.util.Log;
-
-import java.util.HashMap;
-import java.util.Locale;
-
-public class TTS {
-
- private static final String TAG = "TTS";
-
- private TextToSpeech mTts;
- private AudioManager mAudioManager;
-
- public TTS(Context context) {
- mTts = new TextToSpeech(context, new InitListener());
- mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
- }
-
- // TODO: handle speak() calls before service connects
- public void speak(String language, String text) {
-
-
- if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
-
- /* hack for missing TTS -- don't use for official release!
- if (language.equals("bg-BG")) {
- language = "ru-RU";
- }
- if (language.equals("ca-ES")) {
- language = "es-ES"; // hardly politically correct...
- }
- */
-
- /* Google Chinese speech input has a nonstandard code. In output, yue works for Chi in Google, but SVOX uses the standard zh-CN */
- if (language.equals("cmn-Hans-CN")) {
- language = "zh-CN";
- }
-
- Locale locale = LocaleUtils.parseJavaLocale(language.replace('-', '_'),
- Locale.getDefault());
-
- int result = mTts.setLanguage(locale);
- if (result == TextToSpeech.LANG_MISSING_DATA ||
- result == TextToSpeech.LANG_NOT_SUPPORTED) {
- Log.e(TAG, "Language is not available");
- } else {
- HashMap params = new HashMap();
- mTts.speak(text, TextToSpeech.QUEUE_FLUSH, params);
- }
- }
- }
-
- public void destroy() {
- if (mTts != null) {
- mTts.stop();
- mTts.shutdown();
- }
- }
-
- private class InitListener implements TextToSpeech.OnInitListener {
- @Override
- public void onInit(int status) {
- if (status == TextToSpeech.SUCCESS) {
- Log.d(TAG, "Initialized TTS");
- } else {
- Log.e(TAG, "Failed to initialize TTS");
- }
- }
-
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java b/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java
deleted file mode 100644
index 4bfe9690a..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/Translator.java
+++ /dev/null
@@ -1,777 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.util.Log;
-import android.util.Pair;
-import android.net.Uri;
-import android.view.inputmethod.CompletionInfo;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.Cursor;
-
-import org.grammaticalframework.sg.*;
-import org.grammaticalframework.pgf.*;
-import java.io.*;
-import java.util.*;
-
-public class Translator {
-
- private static final String TAG = "Translator";
-
- // new
-
- // TODO: allow changing
- private String mGrammar = "App.pgf" ;
-
- // TODO: build dynamically?
- private Language[] mLanguages = {
- new Language("bg-BG", "Bulgarian", "AppBul", R.xml.cyrillic),
- new Language("ca-ES", "Catalan", "AppCat", R.xml.qwerty),
- new Language("cmn-Hans-CN", "Chinese", "AppChi", R.xml.qwerty),
- // new Language("zh-CN", "Chinese", "AppChi", R.xml.qwerty),
- // new Language("yue", "Chinese (Cantonese)", "AppChi", R.xml.qwerty),
- // new Language("cmn-Hans-CN", "Chinese (Mandarin)", "AppChi", R.xml.qwerty),
- new Language("nl-NL", "Dutch", "AppDut", R.xml.qwerty),
- new Language("en-US", "English", "AppEng", R.xml.qwerty),
- new Language("et-EE", "Estonian","AppEst", R.xml.nordic),
- new Language("fi-FI", "Finnish", "AppFin", R.xml.nordic),
- new Language("fr-FR", "French", "AppFre", R.xml.qwerty), ////
- new Language("de-DE", "German", "AppGer", R.xml.qwerty),
- new Language("hi-IN", "Hindi", "AppHin", R.xml.devanagari_page1, R.xml.devanagari_page2),
- new Language("it-IT", "Italian", "AppIta", R.xml.qwerty),
- new Language("ja-JP", "Japanese","AppJpn", R.xml.qwerty),
- new Language("ru-RU", "Russian", "AppRus", R.xml.cyrillic),
- new Language("es-ES", "Spanish", "AppSpa", R.xml.qwerty),
- new Language("sv-SE", "Swedish", "AppSwe", R.xml.nordic),
- new Language("th-TH", "Thai", "AppTha", R.xml.thai_page1, R.xml.thai_page2),
- new Language("ur-PK", "Urdu", "AppUrd", R.xml.qwerty), // TODO language code and keyboard to check
- };
-
- private Context mContext;
-
- private GrammarLoader mGrammarLoader;
- private ConcrLoader mSourceLoader;
- private ConcrLoader mTargetLoader;
- private ConcrLoader mOtherLoader;
- private SemanticGraphManager mSGManager;
-
- private static final String SOURCE_LANG_KEY = "source_lang";
- private static final String TARGET_LANG_KEY = "target_lang";
-
- public static final String WORDS = "words";
- public static final String SENTENCES = "sentences";
-
- private static final int NUM_ALT_TRANSLATIONS = 10;
-
- private SharedPreferences mSharedPref;
-
- private Language getPrefLang(String key, int def) {
- int index = mSharedPref.getInt(key, def);
- if (index < 0 || index >= mLanguages.length)
- index = def;
- return mLanguages[index];
- }
-
- private void setPrefLang(String key, Language def) {
- for (int index = 0; index < mLanguages.length; index++) {
- if (def == mLanguages[index]) {
- SharedPreferences.Editor editor = mSharedPref.edit();
- editor.putInt(key, index);
- editor.commit();
- break;
- }
- }
- }
-
- public Translator(Context context) {
- mContext = context;
-
- mSharedPref = context.getSharedPreferences(
- context.getString(R.string.global_preferences_key), Context.MODE_PRIVATE);
-
- mGrammarLoader = new GrammarLoader();
- mGrammarLoader.start();
-
- Language prefSourceLang = getPrefLang(SOURCE_LANG_KEY, 0);
- Language prefTargetLang = getPrefLang(TARGET_LANG_KEY, 1);
-
- mSourceLoader = new ConcrLoader(prefSourceLang);
- mSourceLoader.start();
-
- if (prefSourceLang == prefTargetLang) {
- mTargetLoader = mSourceLoader;
- } else {
- mTargetLoader = new ConcrLoader(prefTargetLang);
- mTargetLoader.start();
- }
-
- mOtherLoader = null;
-
- mSGManager = new SemanticGraphManager(context);
- }
-
- public List getAvailableLanguages() {
- return Arrays.asList(mLanguages);
- }
-
- public Language getSourceLanguage() {
- return mSourceLoader.getLanguage();
- }
-
- public void setSourceLanguage(Language language) {
- setPrefLang(SOURCE_LANG_KEY, language);
-
- if (mSourceLoader.getLanguage() == language)
- return;
- if (mTargetLoader.getLanguage() == language) {
- cacheOrUnloadLanguage(mSourceLoader);
- mSourceLoader = mTargetLoader;
- return;
- }
- if (mOtherLoader != null &&
- mOtherLoader.getLanguage() == language) {
- ConcrLoader tmp = mSourceLoader;
- mSourceLoader = mOtherLoader;
- mOtherLoader = tmp;
- return;
- }
-
- try {
- mSourceLoader.join();
- } catch (InterruptedException e) {
- Log.e(TAG, "Loading interrupted", e);
- }
-
- if (mSourceLoader.getLanguage() != mTargetLoader.getLanguage()) {
- cacheOrUnloadLanguage(mSourceLoader);
- }
-
- mSourceLoader = new ConcrLoader(language);
- mSourceLoader.start();
- }
-
- public boolean isSourceLanguageLoaded() {
- try {
- mSourceLoader.join();
- return true;
- } catch (InterruptedException e) {
- Log.e(TAG, "Loading interrupted", e);
- }
- return false;
- }
-
- private Concr getSourceConcr() {
- try {
- mSourceLoader.join();
- } catch (InterruptedException e) {
- Log.e(TAG, "Loading interrupted", e);
- }
- return mSourceLoader.getConcr();
- }
-
- public Language getTargetLanguage() {
- return mTargetLoader.getLanguage();
- }
-
- public void setTargetLanguage(Language language) {
- setPrefLang(TARGET_LANG_KEY, language);
-
- if (mTargetLoader.getLanguage() == language)
- return;
- if (mSourceLoader.getLanguage() == language) {
- cacheOrUnloadLanguage(mTargetLoader);
- mTargetLoader = mSourceLoader;
- return;
- }
- if (mOtherLoader != null &&
- mOtherLoader.getLanguage() == language) {
- ConcrLoader tmp = mTargetLoader;
- mTargetLoader = mOtherLoader;
- mOtherLoader = tmp;
- return;
- }
-
- try {
- mTargetLoader.join();
- } catch (InterruptedException e) {
- Log.e(TAG, "Loading interrupted", e);
- }
-
- if (mSourceLoader.getLanguage() != mTargetLoader.getLanguage()) {
- cacheOrUnloadLanguage(mTargetLoader);
- }
-
- mTargetLoader = new ConcrLoader(language);
- mTargetLoader.start();
- }
-
- public boolean isTargetLanguageLoaded() {
- try {
- mTargetLoader.join();
- return true;
- } catch (InterruptedException e) {
- Log.e(TAG, "Loading interrupted", e);
- }
- return false;
- }
-
- private Concr getTargetConcr() {
- try {
- mTargetLoader.join();
- } catch (InterruptedException e) {
- Log.e(TAG, "Loading interrupted", e);
- }
- return mTargetLoader.getConcr();
- }
-
- private void cacheOrUnloadLanguage(ConcrLoader loader) {
- if (mOtherLoader != null) {
- mOtherLoader.getConcr().unload();
- Log.d(TAG, mOtherLoader.getLanguage().getConcrete() + ".pgf_c unloaded");
- }
- mOtherLoader = loader;
- }
-
- public void switchLanguages() {
- ConcrLoader tmp = mSourceLoader;
- mSourceLoader = mTargetLoader;
- mTargetLoader = tmp;
- }
-
- private static String explode(String in) {
- String out = "";
- for (int i = 0; i < in.length(); i++) {
- if (i > 0)
- out += ' ';
- out += in.charAt(i);
- }
- return out;
- }
-
- private static String implode(String s) {
- return s.replaceAll("(? iter = sourceLang.parse("Chunk", input).iterator(); // try parse as chunk
- Expr expr = iter.next().getExpr();
- output = targetLang.linearize(expr);
- return output ;
- } catch (ParseError e) { // if this fails
- List morphos = lookupMorpho(input) ; // lookup morphological analyses
-
- morphos.addAll(lookupMorpho(lowerinput)) ; // including the analyses of the lower-cased word
-
- for (MorphoAnalysis ana : morphos) {
- if (targetLang.hasLinearization(ana.getLemma())) { // check that the word has linearization in target
- output = targetLang.linearize(Expr.readExpr(ana.getLemma())) ;
- break ; // if yes, don't search any more
- }
- }
- return output ;
- }
- }
-
- private String translateByLookup(String input) {
- String[] words = input.split(" ") ;
-
- String output = "%" ;
- for (String w : words) {
- output = output + " " + translateWord(w) ;
- }
-
- return output ;
- }
-
- // lowercase the first word if (1) it is not in the lexicon and (2) its lowercase version is in the lexicon
- // otherwise it will be left uppercase and treated as a name
- private String lowercaseIfBetter(String input) {
- String[] words = input.split(" ") ;
-
- String firstword = words[0] ;
-
- String lowerfirstword = firstword.toLowerCase() ;
-
- if (lookupMorpho(firstword).isEmpty() && !(lookupMorpho(lowerfirstword).isEmpty())) {
- words[0] = lowerfirstword ;
- String output = "" ;
- for (String w : words) {
- output = output + " " + w ;
- }
- return output ;
- } else {
- return input ;
- }
-
- }
-
- /**
- * Takes a lot of time. Must not be called on the main thread.
- */
- public Pair> translate(String input) {
- if (getSourceLanguage().getLangCode().equals("cmn-Hans-CN")) {
- // for Chinese we need to put space after every character
- input = explode(input);
- } else {
- input = lowercaseIfBetter(input);
- } ;
-
- String output = null;
- List exprs = new ArrayList();
-
- try {
- Concr sourceLang = getSourceConcr();
- Concr targetLang = getTargetConcr();
-
- Map callbacks = new HashMap();
- callbacks.put("PN", new NercLiteralCallback(mGrammarLoader.getGrammar(), sourceLang, input));
- callbacks.put("Symb", new UnknownLiteralCallback(sourceLang, input));
-
- int count = NUM_ALT_TRANSLATIONS;
- for (ExprProb ep : sourceLang.parseWithHeuristics(getGrammar().getStartCat(), input, -1, callbacks)) {
- if (count-- <= 0)
- break;
- exprs.add(ep);
- if (output == null)
- output = targetLang.linearize(ep.getExpr());
- }
- } catch (ParseError e) {
- output = translateByLookup(input);
- }
-
- if (output == null)
- output = "% "; // make sure that we return something
-
- if (getTargetLanguage().getLangCode().equals("cmn-Hans-CN") ||
- getTargetLanguage().getLangCode().equals("ja-JP") ||
- getTargetLanguage().getLangCode().equals("th-TH"))
- output = implode(output) ;
-
- return new Pair>(output, exprs);
- }
-
- public String linearize(Expr expr) {
- Concr targetLang = getTargetConcr();
- String s = targetLang.linearize(expr);
- if (s == null)
- s = "% "; // make sure that we return something
-
- if (getTargetLanguage().getLangCode().equals("cmn-Hans-CN") ||
- getTargetLanguage().getLangCode().equals("ja-JP") ||
- getTargetLanguage().getLangCode().equals("th-TH"))
- return implode(s);
- else
- return s;
- }
-
- public String linearizeSource(Expr expr) {
- Concr targetLang = getSourceConcr();
- String s = targetLang.linearize(expr);
- if (s == null)
- s = "% "; // make sure that we return something
-
- if (getSourceLanguage().getLangCode().equals("cmn-Hans-CN") ||
- getSourceLanguage().getLangCode().equals("ja-JP") ||
- getSourceLanguage().getLangCode().equals("th-TH"))
- return implode(s);
- else
- return s;
- }
-
- public Object[] bracketedLinearize(Expr expr) {
- Concr targetLang = getTargetConcr();
- return targetLang.bracketedLinearize(expr);
- }
-
- public String generateLexiconEntry(Expr lemma) {
- Concr sourceLang = getSourceConcr();
- Concr targetLang = getTargetConcr();
- String fun = lemma.toString();
- String cat = getGrammar().getFunctionType(fun).getCategory();
-
- Expr e2 = Expr.readExpr("MkTag (Inflection"+cat+" "+fun+")");
-
- if (targetLang.hasLinearization("Inflection"+cat)) {
- if (targetLang.hasLinearization(fun))
- return sourceLang.linearize(lemma) + " - " + targetLang.linearize(e2) + ". " + targetLang.linearize(lemma);
- else
- return sourceLang.linearize(lemma) + " " + targetLang.linearize(e2)+".";
- } else {
- if (targetLang.hasLinearization(fun))
- return sourceLang.linearize(lemma) + " - " + targetLang.linearize(lemma);
- else
- return sourceLang.linearize(lemma);
- }
- }
-
- private static final Expr gloss_pred = Expr.readExpr("gloss");
- private static final Expr topic_pred = Expr.readExpr("topic");
- private static final Expr example_pred = Expr.readExpr("example");
-
- public Expr getDefinition(Expr lemma, boolean withExample) {
- Expr gloss = null;
- Expr example = null;
- Map topics = new TreeMap();
-
- try {
- TripleResult res = mSGManager.queryTriple(lemma, null, null);
- while (res.hasNext()) {
- if (res.getPredicate().equals(gloss_pred))
- gloss = res.getObject();
- else if (res.getPredicate().equals(topic_pred))
- updateWordsMap(res.getObject(), topics);
- else if (res.getPredicate().equals(example_pred))
- example = res.getObject();
- }
- res.close();
- } catch (IOException e) {
- // nothing
- } catch (SGError e) {
- // nothing
- }
-
- Expr topic = null;
- if (topics.size() > 0) {
- StringBuilder builder = new StringBuilder();
- builder.append('(');
- buildWordsHtml(topics, builder);
- builder.append(')');
- topic = new Expr(builder.toString());
- }
- if (gloss == null)
- return topic;
- else {
- if (topic == null)
- topic = new Expr("");
- if (withExample && example != null)
- return new Expr("MkDefinitionEx", topic, gloss, example);
- else
- return new Expr("MkDefinition", topic, gloss);
- }
- }
-
- private void updateWordsMap(Expr expr, Map map) {
- String word = getTargetConcr().linearize(expr);
-
- Uri.Builder builder = map.get(word);
- if (builder == null) {
- builder = new Uri.Builder();
- builder.scheme("gf-translator");
- builder.authority(WORDS);
- builder.appendQueryParameter("source", word);
- map.put(word,builder);
- }
- builder.appendQueryParameter("alternative", expr.toString());
- }
-
- private void buildWordsHtml(Map map, StringBuilder sbuilder) {
- boolean first = true;
- for (Map.Entry entry : map.entrySet()) {
- if (first)
- first = false;
- else
- sbuilder.append(", ");
-
- sbuilder.append(""+entry.getKey()+" ");
- }
- }
-
- public List getTopicWords(Expr lemma) {
- TripleResult res = null;
- List words = new ArrayList();
- try {
- res = mSGManager.queryTriple(null, topic_pred, lemma);
- while (res.hasNext()) {
- words.add(res.getSubject());
- }
- } catch (IOException e) {
- // nothing
- } catch (SGError e) {
- // nothing
- } finally {
- if (res != null)
- res.close();
- }
- return words;
- }
-
- private Expr getTopicWordsHtml(Expr lemma) {
- StringBuilder sbuilder = new StringBuilder();
- TripleResult res = null;
- try {
- res = mSGManager.queryTriple(null, topic_pred, lemma);
- Map map = new TreeMap();
- while (res.hasNext()) {
- updateWordsMap(res.getSubject(), map);
- }
-
- StringBuilder builder = new StringBuilder();
- buildWordsHtml(map, builder);
- return new Expr(builder.toString());
- } catch (IOException e) {
- // nothing
- } catch (SGError e) {
- // nothing
- } finally {
- if (res != null)
- res.close();
- }
- return null;
- }
-
- public String getInflectionTable(Expr lemma) {
- boolean withExample =
- (getSourceLanguage().getLangCode().equals("en-US") ||
- getTargetLanguage().getLangCode().equals("en-US"));
- Expr def =
- getDefinition(lemma, withExample);
-
- String fun = lemma.toString();
- Concr targetLang = getTargetConcr();
- String cat = getGrammar().getFunctionType(fun).getCategory();
-
- if (targetLang.hasLinearization(fun) &&
- targetLang.hasLinearization("Inflection"+cat)) {
- if (def == null)
- def = Expr.readExpr("NoDefinition");
-
- Expr e = new Expr("MkDocument",
- def,
- new Expr("Inflection"+cat,lemma),
- getTopicWordsHtml(lemma));
- String html =
- " " +
- targetLang.linearize(e) +
- "";
- return html;
- } else if (def != null) {
- String html =
- " " +
- targetLang.linearize(def) +
- "";
- return html;
- } else {
- return null;
- }
- }
-
- public List getTopicsOf(Expr lemma) {
- TripleResult res = null;
- List topics = new ArrayList();
- try {
- res = mSGManager.queryTriple(lemma, topic_pred, null);
- while (res.hasNext()) {
- topics.add(res.getObject());
- }
- } catch (IOException e) {
- // nothing
- } catch (SGError e) {
- // nothing
- } finally {
- if (res != null)
- res.close();
- }
- return topics;
- }
-
- private static String escapeHtml(CharSequence text) {
- StringBuilder out = new StringBuilder();
-
- for (int i = 0; i < text.length(); i++) {
- char c = text.charAt(i);
-
- if (c == '<') {
- out.append("<");
- } else if (c == '>') {
- out.append(">");
- } else if (c == '&') {
- out.append("&");
- } else if (c == '"') {
- out.append(""");
- } else if (c > 0x7E || c < ' ') {
- out.append("").append((int) c).append(";");
- } else if (c == ' ') {
- while (i + 1 < text.length() && text.charAt(i + 1) == ' ') {
- out.append(" ");
- i++;
- }
-
- out.append(' ');
- } else {
- out.append(c);
- }
- }
-
- return out.toString();
- }
-
- public List lookupMorpho(String sentence) {
- List ans = getSourceConcr().lookupMorpho(sentence);
- Collections.sort(ans, new Comparator() {
- public int compare(MorphoAnalysis a1, MorphoAnalysis a2) {
- if (a1.getProb() > a2.getProb())
- return 1;
- else if (a1.getProb() < a2.getProb())
- return -1;
- else
- return 0;
- }
- });
- return ans;
- }
-
- public CompletionInfo[] lookupWordPrefix(String prefix) {
- PriorityQueue queue =
- new PriorityQueue(500, new Comparator() {
- @Override
- public int compare(FullFormEntry lhs, FullFormEntry rhs) {
- return Double.compare(lhs.getProb(), rhs.getProb());
- }
- });
- for (FullFormEntry entry : getSourceConcr().lookupWordPrefix(prefix)) {
- queue.add(entry);
- if (queue.size() >= 1000)
- break;
- }
-
- CompletionInfo[] completions = new CompletionInfo[Math.min(queue.size(), 5)+1];
- completions[0] = new CompletionInfo(0, 0, prefix);
- for (int i = 1; i < completions.length; i++) {
- completions[i] = new CompletionInfo(i,i,queue.poll().getForm());
- }
-
- if (completions.length > 1) {
- Arrays.sort(completions, 1, completions.length-1, new Comparator() {
- @Override
- public int compare(CompletionInfo arg0, CompletionInfo arg1) {
- return ((String) arg0.getText()).compareTo((String) arg1.getText());
- }
- });
- }
-
- return completions;
- }
-
- private PGF getGrammar() {
- try {
- mGrammarLoader.join();
- } catch (InterruptedException e) {
- Log.e(TAG, "Loading interrupted", e);
- }
- return mGrammarLoader.getGrammar();
- }
-
- private class GrammarLoader extends Thread {
- private PGF mPGF;
-
- public GrammarLoader() {
- mPGF = null;
- }
-
- public PGF getGrammar() {
- return mPGF;
- }
-
- public void run() {
- InputStream in = null;
-
- try {
- in = mContext.getAssets().open(mGrammar);
- Log.d(TAG, "Trying to open " + mGrammar);
- long t1 = System.currentTimeMillis();
- mPGF = PGF.readPGF(in);
- long t2 = System.currentTimeMillis();
- Log.d(TAG, mGrammar + " loaded ("+(t2-t1)+" ms)");
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File not found", e);
- } catch (IOException e) {
- Log.e(TAG, "Error loading grammar", e);
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- Log.e(TAG, "Error closing the stream", e);
- }
- }
- }
- }
- }
-
- private class ConcrLoader extends Thread {
- private Language mLanguage;
- private Concr mConcr;
-
- public ConcrLoader(Language lang) {
- this.mLanguage = lang;
- this.mConcr = null;
- }
-
- public Language getLanguage() {
- return mLanguage;
- }
-
- public Concr getConcr() {
- return mConcr;
- }
-
- public void run() {
- try {
- mGrammarLoader.join();
- } catch (InterruptedException e) {
- Log.d(TAG, "interrupted", e);
- }
-
- InputStream in = null;
-
- try {
- String name = mLanguage.getConcrete()+".pgf_c";
- in = mContext.getAssets().open(name);
- Log.d(TAG, "Trying to load " + name);
- long t1 = System.currentTimeMillis();
- mConcr = mGrammarLoader.getGrammar().getLanguages().get(mLanguage.getConcrete());
- mConcr.load(in);
- long t2 = System.currentTimeMillis();
- Log.d(TAG, name + " loaded ("+(t2-t1)+" ms)");
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File not found", e);
- } catch (IOException e) {
- Log.e(TAG, "Error loading concrete", e);
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- Log.e(TAG, "Error closing the stream", e);
- }
- }
- }
- }
- }
-
- public boolean isUpgraded(String key) {
- int old_code = mSharedPref.getInt(key, 0);
-
- int new_code = 0;
- try {
- new_code = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionCode;
- } catch (NameNotFoundException e) {
- // Huh? Really?
- }
-
- SharedPreferences.Editor editor = mSharedPref.edit();
- editor.putInt(key, new_code);
- editor.commit();
-
- return (old_code != new_code);
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/TranslatorInputMethodService.java b/src/ui/android/src/org/grammaticalframework/ui/android/TranslatorInputMethodService.java
deleted file mode 100644
index d621e2f69..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/TranslatorInputMethodService.java
+++ /dev/null
@@ -1,666 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import android.inputmethodservice.InputMethodService;
-import android.text.InputType;
-import android.text.method.MetaKeyKeyListener;
-import android.view.KeyCharacterMap;
-import android.view.KeyEvent;
-import android.view.View;
-import android.view.inputmethod.CompletionInfo;
-import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputConnection;
-
-
-public class TranslatorInputMethodService extends InputMethodService
- implements android.inputmethodservice.KeyboardView.OnKeyboardActionListener {
-
- private TranslatorKeyboardView mInputView;
- private CompletionsView mCandidateView;
- private CompletionInfo[] mCompletions;
-
- private StringBuilder mComposingText = new StringBuilder();
- private StringBuilder mComposingWord = new StringBuilder();
- private boolean mPredictionOn;
- private boolean mCompletionOn;
- private boolean mCapsLock;
- private long mLastShiftTime;
- private long mMetaState;
-
- private TranslatorKeyboard mSymbolsPage1Keyboard;
- private TranslatorKeyboard mSymbolsPage2Keyboard;
- private TranslatorKeyboard mLanguagePage1Keyboard;
- private TranslatorKeyboard mLanguagePage2Keyboard;
-
- private TranslatorKeyboard mCurKeyboard;
-
- private int mActionId;
-
- private Translator mTranslator;
-
- @Override
- public void onCreate() {
- super.onCreate();
-
- mTranslator = ((GFTranslator) getApplicationContext()).getTranslator();
-
- mSymbolsPage1Keyboard = null;
- mSymbolsPage2Keyboard = null;
- mLanguagePage1Keyboard = null;
- mLanguagePage2Keyboard = null;
- }
-
- @Override
- public View onCreateInputView() {
- mInputView = (TranslatorKeyboardView)
- getLayoutInflater().inflate(R.layout.input, null);
- mInputView.setOnKeyboardActionListener(this);
- mInputView.setKeyboard(mCurKeyboard);
- return mInputView;
- }
-
- @Override
- public View onCreateCandidatesView() {
- mCandidateView = new CompletionsView(this);
- mCandidateView.setService(this);
- return mCandidateView;
- }
-
- private int mModeId;
- private EditorInfo mAttribute;
- private static TranslatorInputMethodService mInstance;
-
- static TranslatorInputMethodService getInstance() {
- return mInstance;
- }
-
- @Override
- public void onStartInput(EditorInfo attribute, boolean restarting) {
- super.onStartInput(attribute, restarting);
-
- // Reset our state. We want to do this even if restarting, because
- // the underlying state of the text editor could have changed in any way.
- mComposingText.setLength(0);
- mComposingWord.setLength(0);
- updateCandidates();
-
- if (!restarting) {
- // Clear shift states.
- mMetaState = 0;
- }
-
- mPredictionOn = false;
- mCompletionOn = false;
- mCompletions = null;
-
- int res1 =
- mTranslator.getSourceLanguage().getKeyboardPage1Resource();
- int res2 =
- mTranslator.getSourceLanguage().getKeyboardPage2Resource();
- mModeId = R.string.normalKeyboardMode;
- if (attribute.extras != null &&
- !attribute.extras.getBoolean("show_language_toggle", true)) {
- mModeId = R.string.internalKeyboardMode;
- }
- mAttribute = attribute;
- mLanguagePage1Keyboard = new TranslatorKeyboard(this, res1, mModeId);
- mLanguagePage2Keyboard = new TranslatorKeyboard(this, res2, mModeId);
- mSymbolsPage1Keyboard = new TranslatorKeyboard(this, R.xml.symbols_page1, mModeId);
- mSymbolsPage2Keyboard = new TranslatorKeyboard(this, R.xml.symbols_page2, mModeId);
-
- // We are now going to initialize our state based on the type of
- // text being edited.
- switch (attribute.inputType & InputType.TYPE_MASK_CLASS) {
- case InputType.TYPE_CLASS_NUMBER:
- case InputType.TYPE_CLASS_DATETIME:
- // Numbers and dates default to the symbols keyboard, with
- // no extra features.
- mCurKeyboard = mSymbolsPage1Keyboard;
- break;
-
- case InputType.TYPE_CLASS_PHONE:
- // Phones will also default to the symbols keyboard, though
- // often you will want to have a dedicated phone keyboard.
- mCurKeyboard = mSymbolsPage1Keyboard;
- break;
-
- case InputType.TYPE_CLASS_TEXT:
- // This is general text editing. We will default to the
- // normal alphabetic keyboard, and assume that we should
- // be doing predictive text (showing candidates as the
- // user types).
- mCurKeyboard = mLanguagePage1Keyboard;
- mPredictionOn = true;
-
- // We now look for a few special variations of text that will
- // modify our behavior.
- int variation = attribute.inputType & InputType.TYPE_MASK_VARIATION;
- if (variation == InputType.TYPE_TEXT_VARIATION_PASSWORD ||
- variation == InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD ||
- variation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
- // Do not display predictions / what the user is typing
- // when they are entering a password.
- mPredictionOn = false;
- }
-
- if (variation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS ||
- variation == InputType.TYPE_TEXT_VARIATION_URI ||
- variation == InputType.TYPE_TEXT_VARIATION_FILTER) {
- // Our predictions are not useful for e-mail addresses
- // or URIs.
- mPredictionOn = false;
- }
-
- if ((attribute.inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) {
- // If this is an auto-complete text view, then our predictions
- // will not be shown and instead we will allow the editor
- // to supply their own. We only show the editor's
- // candidates when in full-screen mode, otherwise relying
- // own it displaying its own UI.
- mPredictionOn = false;
- mCompletionOn = isFullscreenMode();
- }
-
- // We also want to look at the current state of the editor
- // to decide whether our alphabetic keyboard should start out
- // shifted.
- updateShiftKeyState(attribute);
- break;
-
- default:
- // For all unknown input types, default to the alphabetic
- // keyboard with no special features.
- mCurKeyboard = mLanguagePage1Keyboard;
- updateShiftKeyState(attribute);
- }
-
- mActionId = attribute.imeOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
- mLanguagePage1Keyboard.setImeOptions(getResources(), attribute.imeOptions);
- mLanguagePage2Keyboard.setImeOptions(getResources(), attribute.imeOptions);
-
- mInstance = this;
- }
-
- @Override
- public void onFinishInput() {
- super.onFinishInput();
-
- // Clear current composing text and candidates.
- mComposingText.setLength(0);
- mComposingWord.setLength(0);
- updateCandidates();
-
- // We only hide the candidates window when finishing input on
- // a particular editor, to avoid popping the underlying application
- // up and down if the user is entering text into the bottom of
- // its window.
- setCandidatesViewShown(false);
-
- mCurKeyboard = mLanguagePage1Keyboard;
- if (mInputView != null) {
- mInputView.closing();
- }
-
- mInstance = null;
- mAttribute = null;
- }
-
- @Override
- public void onStartInputView(EditorInfo attribute, boolean restarting) {
- super.onStartInputView(attribute, restarting);
- // Apply the selected keyboard to the input view.
- mInputView.setKeyboard(mCurKeyboard);
- mInputView.closing();
- }
-
- @Override
- public void onUpdateSelection(int oldSelStart, int oldSelEnd,
- int newSelStart, int newSelEnd,
- int candidatesStart, int candidatesEnd) {
- super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
- candidatesStart, candidatesEnd);
-
- // If the current selection in the text view changes, we should
- // clear whatever candidate text we have.
- if (mComposingText.length() + mComposingWord.length() > 0 &&
- (newSelStart != candidatesEnd || newSelEnd != candidatesEnd)) {
- mComposingText.setLength(0);
- mComposingWord.setLength(0);
- updateCandidates();
- InputConnection ic = getCurrentInputConnection();
- if (ic != null) {
- ic.finishComposingText();
- }
- }
- }
-
- @Override
- public void onDisplayCompletions(CompletionInfo[] completions) {
- if (mCompletionOn) {
- mCompletions = completions;
- if (completions == null) {
- setSuggestions(null, false, false);
- return;
- }
-
- setSuggestions(completions, true, true);
- }
- }
-
- /**
- * This translates incoming hard key events in to edit operations on an
- * InputConnection. It is only needed when using the
- * PROCESS_HARD_KEYS option.
- */
- private boolean translateKeyDown(int keyCode, KeyEvent event) {
- mMetaState = MetaKeyKeyListener.handleKeyDown(mMetaState,
- keyCode, event);
- int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(mMetaState));
- mMetaState = MetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
- InputConnection ic = getCurrentInputConnection();
- if (c == 0 || ic == null) {
- return false;
- }
-
- if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) {
- c = c & KeyCharacterMap.COMBINING_ACCENT_MASK;
- }
-
- if (mComposingWord.length() > 0) {
- char accent = mComposingWord.charAt(mComposingWord.length()-1);
- int composed = KeyEvent.getDeadChar(accent, c);
-
- if (composed != 0) {
- c = composed;
- mComposingWord.setLength(mComposingWord.length()-1);
- }
- }
-
- onKey(c, null);
-
- return true;
- }
-
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- switch (keyCode) {
- case KeyEvent.KEYCODE_BACK:
- // The InputMethodService already takes care of the back
- // key for us, to dismiss the input method if it is shown.
- // However, our keyboard could be showing a pop-up window
- // that back should dismiss, so we first allow it to do that.
- if (event.getRepeatCount() == 0 && mInputView != null) {
- if (mInputView.handleBack()) {
- return true;
- }
- }
- break;
-
- case KeyEvent.KEYCODE_DEL:
- // Special handling of the delete key: if we currently are
- // composing text for the user, we want to modify that instead
- // of let the application to the delete itself.
- if (mComposingText.length() + mComposingWord.length() > 0) {
- onKey(TranslatorKeyboard.KEYCODE_DELETE, null);
- return true;
- }
- break;
-
- case KeyEvent.KEYCODE_ENTER:
- // Let the underlying text editor always handle these.
- return false;
-
- default:
- if (mPredictionOn && translateKeyDown(keyCode, event)) {
- return true;
- }
- }
-
- return super.onKeyDown(keyCode, event);
- }
-
- /**
- * Helper function to commit any text being composed in to the editor.
- */
- private void commitTyped(InputConnection inputConnection) {
- if (mComposingText.length() + mComposingWord.length() > 0) {
- String s = getComposingString();
- inputConnection.commitText(s, s.length());
- mComposingText.setLength(0);
- mComposingWord.setLength(0);
- updateCandidates();
- }
- }
-
- /**
- * Helper to update the shift state of our keyboard based on the initial
- * editor state.
- */
- private void updateShiftKeyState(EditorInfo attr) {
- if (attr != null && mInputView != null &&
- (mLanguagePage1Keyboard == mInputView.getKeyboard() ||
- mLanguagePage2Keyboard == mInputView.getKeyboard())) {
- int caps = 0;
- EditorInfo ei = getCurrentInputEditorInfo();
- if (ei != null && ei.inputType != InputType.TYPE_NULL) {
- caps = getCurrentInputConnection().getCursorCapsMode(attr.inputType);
- }
- mInputView.setShifted(mCapsLock || caps != 0);
- }
- }
-
- /**
- * Helper to send a key down / key up pair to the current editor.
- */
- private void keyDownUp(int keyEventCode) {
- getCurrentInputConnection().sendKeyEvent(
- new KeyEvent(KeyEvent.ACTION_DOWN, keyEventCode));
- getCurrentInputConnection().sendKeyEvent(
- new KeyEvent(KeyEvent.ACTION_UP, keyEventCode));
- }
-
- // Implementation of KeyboardViewListener
- public void onKey(int primaryCode, int[] keyCodes) {
- if (primaryCode == TranslatorKeyboard.KEYCODE_DELETE) {
- handleBackspace();
- } else if (primaryCode == TranslatorKeyboard.KEYCODE_SHIFT) {
- handleShift();
- } else if (primaryCode == TranslatorKeyboard.KEYCODE_SOURCE_LANGUAGE
- && mInputView != null) {
- mTranslator.switchLanguages();
- handleSwitchLanguages();
- } else if (primaryCode < TranslatorKeyboard.KEYCODE_SOURCE_LANGUAGE &&
- primaryCode > TranslatorKeyboard.KEYCODE_SOURCE_LANGUAGE-TranslatorKeyboard.MAX_LANGUAGE_KEYCODES) {
- Language newSource =
- mTranslator.getAvailableLanguages().get(TranslatorKeyboard.KEYCODE_SOURCE_LANGUAGE-primaryCode-1);
- mTranslator.setSourceLanguage(newSource);
- handleChangeSourceLanguage(newSource);
- } else if (primaryCode == TranslatorKeyboard.KEYCODE_TARGET_LANGUAGE) {
- String translation = mTranslator.translate(getComposingString()).first;
- if (translation.startsWith("% ") || translation.startsWith("* ") || translation.startsWith("+ "))
- translation = translation.substring(2);
- getCurrentInputConnection().commitText(translation, 1);
- return;
- } else if (primaryCode < TranslatorKeyboard.KEYCODE_TARGET_LANGUAGE &&
- primaryCode > TranslatorKeyboard.KEYCODE_TARGET_LANGUAGE-TranslatorKeyboard.MAX_LANGUAGE_KEYCODES) {
- Language newTarget =
- mTranslator.getAvailableLanguages().get(TranslatorKeyboard.KEYCODE_TARGET_LANGUAGE-primaryCode-1);
- mTranslator.setTargetLanguage(newTarget);
- handleChangeTargetLanguage(newTarget);
- } else if (primaryCode == TranslatorKeyboard.KEYCODE_MODE_CHANGE &&
- mInputView != null) {
- TranslatorKeyboard current = (TranslatorKeyboard) mInputView.getKeyboard();
- if (current == mSymbolsPage1Keyboard || current == mSymbolsPage2Keyboard) {
- current = mLanguagePage1Keyboard;
- } else {
- current = mSymbolsPage1Keyboard;
- }
- mInputView.setKeyboard(current);
- if (current == mSymbolsPage1Keyboard) {
- current.setShifted(false);
- }
- } else if (primaryCode == TranslatorKeyboard.KEYCODE_PAGE_CHANGE &&
- mInputView != null) {
- TranslatorKeyboard current = (TranslatorKeyboard) mInputView.getKeyboard();
- if (current == mLanguagePage1Keyboard) {
- current = mLanguagePage2Keyboard;
- } else {
- current = mLanguagePage1Keyboard;
- }
- mInputView.setKeyboard(current);
- } else if (primaryCode == 10) {
- if ((mActionId & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0)
- getCurrentInputConnection().performEditorAction(mActionId & EditorInfo.IME_MASK_ACTION);
- else
- handleCharacter(primaryCode, keyCodes);
- } else if (primaryCode == ' ') {
- if (mComposingText.length() + mComposingWord.length() == 0)
- getCurrentInputConnection().commitText(" ", 1);
- else if (mComposingWord.length() > 0) {
- mComposingText.append(mComposingWord);
- mComposingText.append(' ');
- mComposingWord.setLength(0);
- getCurrentInputConnection().setComposingText(getComposingString(), 1);
- } else {
- mComposingText.append(' ');
- getCurrentInputConnection().setComposingText(getComposingString(), 1);
- }
- } else {
- handleCharacter(primaryCode, keyCodes);
- }
- }
-
- public void onText(CharSequence text) {
- InputConnection ic = getCurrentInputConnection();
- if (ic == null) return;
- ic.beginBatchEdit();
- if (mComposingText.length() > 0) {
- commitTyped(ic);
- }
- ic.commitText(text, 0);
- ic.endBatchEdit();
- updateShiftKeyState(getCurrentInputEditorInfo());
- }
-
- /**
- * Update the list of available candidates from the current composing
- * text. This will need to be filled in by however you are determining
- * candidates.
- */
- private void updateCandidates() {
- if (!mCompletionOn) {
- if (mComposingWord.length() > 1) {
- mCompletions =
- mTranslator.lookupWordPrefix(mComposingWord.toString());
- setSuggestions(mCompletions, true, true);
- } else {
- setSuggestions(null, false, false);
- }
- }
- }
-
- public void setSuggestions(CompletionInfo[] completions, boolean isCompletions,
- boolean typedWordValid) {
- if (completions != null && completions.length > 0) {
- setCandidatesViewShown(true);
- } else if (isExtractViewShown()) {
- setCandidatesViewShown(true);
- }
- if (mCandidateView != null) {
- mCandidateView.setSuggestions(completions, isCompletions, typedWordValid);
- }
- }
-
- private void handleBackspace() {
- int wordLength = mComposingWord.length();
- int textLength = mComposingText.length();
- if (wordLength > 1) {
- mComposingWord.delete(wordLength - 1, wordLength);
- getCurrentInputConnection().setComposingText(getComposingString(), 1);
- if (mPredictionOn)
- updateCandidates();
- } else if (wordLength > 0) {
- mComposingWord.setLength(0);
- getCurrentInputConnection().setComposingText(getComposingString(), 1);
- updateCandidates();
- } else if (textLength > 0) {
- if (mComposingText.charAt(textLength - 1) == ' ') {
- mComposingText.delete(textLength - 1, textLength);
- getCurrentInputConnection().setComposingText(getComposingString(), 1);
- } else {
- mComposingText.delete(textLength - 1, textLength);
- textLength--;
- int index = mComposingText.lastIndexOf(" ");
- if (index == -1) {
- mComposingWord.append(mComposingText.toString());
- mComposingText.setLength(0);
- } else {
- mComposingWord.append(mComposingText.substring(index+1, textLength));
- mComposingText.delete(index+1, textLength);
- }
- getCurrentInputConnection().setComposingText(getComposingString(), 1);
- }
- updateCandidates();
- } else {
- keyDownUp(KeyEvent.KEYCODE_DEL);
- }
- updateShiftKeyState(getCurrentInputEditorInfo());
- }
-
- private void handleShift() {
- if (mInputView == null) {
- return;
- }
-
- TranslatorKeyboard currentKeyboard = (TranslatorKeyboard) mInputView.getKeyboard();
- if (mLanguagePage1Keyboard == currentKeyboard ||
- mLanguagePage2Keyboard == currentKeyboard) {
- // Alphabet keyboard
- checkToggleCapsLock();
- mInputView.setShifted(mCapsLock || !mInputView.isShifted());
- } else if (currentKeyboard == mSymbolsPage1Keyboard) {
- mSymbolsPage1Keyboard.setShifted(true);
- mInputView.setKeyboard(mSymbolsPage2Keyboard);
- mSymbolsPage2Keyboard.setShifted(true);
- } else if (currentKeyboard == mSymbolsPage2Keyboard) {
- mSymbolsPage2Keyboard.setShifted(false);
- mInputView.setKeyboard(mSymbolsPage1Keyboard);
- mSymbolsPage1Keyboard.setShifted(false);
- }
- }
-
- private String getComposingString() {
- return mComposingText.toString() + mComposingWord.toString();
- }
-
- private void handleCharacter(int primaryCode, int[] keyCodes) {
- if (keyCodes.length > 0 && keyCodes[0] > 0) {
- for (int i = 0; i < keyCodes.length && keyCodes[i] > 0; i++) {
- int code = keyCodes[i];
- if (mInputView.isShifted())
- code = Character.toUpperCase(code);
- mComposingWord.append((char) code);
- }
- } else {
- if (mInputView.isShifted())
- primaryCode = Character.toUpperCase(primaryCode);
- mComposingWord.append((char) primaryCode);
- }
-
- if (primaryCode == 10)
- commitTyped(getCurrentInputConnection());
- else
- getCurrentInputConnection().setComposingText(getComposingString(), 1);
- updateShiftKeyState(getCurrentInputEditorInfo());
-
- if (mPredictionOn) {
- updateCandidates();
- }
- }
-
- private void handleClose() {
- commitTyped(getCurrentInputConnection());
- requestHideSelf(0);
- mInputView.closing();
- }
-
- void handleChangeSourceLanguage(Language newSource) {
- updateLanguageKeyboard(newSource);
- mSymbolsPage1Keyboard.updateLanguageKeyLabels();
- mSymbolsPage2Keyboard.updateLanguageKeyLabels();
- if (mInputView != null) {
- mInputView.setKeyboard(mCurKeyboard);
- }
- }
-
- void handleChangeTargetLanguage(Language newTarget) {
- mLanguagePage1Keyboard.updateLanguageKeyLabels();
- mLanguagePage2Keyboard.updateLanguageKeyLabels();
- mSymbolsPage1Keyboard.updateLanguageKeyLabels();
- mSymbolsPage2Keyboard.updateLanguageKeyLabels();
- if (mInputView != null) {
- mInputView.invalidateAllKeys();
- }
- }
-
- void handleSwitchLanguages() {
- Language newSource = mTranslator.getSourceLanguage();
- updateLanguageKeyboard(newSource);
- mSymbolsPage1Keyboard.updateLanguageKeyLabels();
- mSymbolsPage2Keyboard.updateLanguageKeyLabels();
- if (mInputView != null)
- mInputView.setKeyboard(mCurKeyboard);
- }
-
- private void updateLanguageKeyboard(Language language) {
- TranslatorKeyboard keyboard1 =
- new TranslatorKeyboard(this, language.getKeyboardPage1Resource(), mModeId);
- TranslatorKeyboard keyboard2 =
- new TranslatorKeyboard(this, language.getKeyboardPage2Resource(), mModeId);
- keyboard1.setImeOptions(getResources(), mAttribute.imeOptions);
- keyboard2.setImeOptions(getResources(), mAttribute.imeOptions);
- if (mCurKeyboard == mLanguagePage1Keyboard) {
- mCurKeyboard = keyboard1;
- } else if (mCurKeyboard == mLanguagePage2Keyboard) {
- mCurKeyboard = keyboard2;
- }
- mLanguagePage1Keyboard = keyboard1;
- mLanguagePage2Keyboard = keyboard2;
- }
-
- private void checkToggleCapsLock() {
- long now = System.currentTimeMillis();
- if (mLastShiftTime + 800 > now) {
- mCapsLock = !mCapsLock;
- mLastShiftTime = 0;
- } else {
- mLastShiftTime = now;
- }
- }
-
- public void pickDefaultCandidate() {
- pickSuggestionManually(0);
- }
-
- public void pickSuggestionManually(int index) {
- if (mCompletions != null &&
- index >= 0 && index < mCompletions.length) {
- CompletionInfo ci = mCompletions[index];
-
- if (mCompletionOn)
- getCurrentInputConnection().commitCompletion(ci);
- else {
- mComposingWord.setLength(0);
- mComposingWord.append(ci.getText());
- getCurrentInputConnection().setComposingText(getComposingString(), 1);
- }
-
- if (mCandidateView != null) {
- mCandidateView.clear();
- }
- updateShiftKeyState(getCurrentInputEditorInfo());
- }
- }
-
- public void swipeRight() {
- if (mCompletionOn) {
- pickDefaultCandidate();
- }
- }
-
- public void swipeLeft() {
- handleBackspace();
- }
-
- public void swipeDown() {
- handleClose();
- }
-
- public void swipeUp() {
- }
-
- public void onPress(int primaryCode) {
- }
-
- public void onRelease(int primaryCode) {
- }
-}
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/TranslatorKeyboard.java b/src/ui/android/src/org/grammaticalframework/ui/android/TranslatorKeyboard.java
deleted file mode 100644
index 876f660da..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/TranslatorKeyboard.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import java.util.Locale;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.content.res.XmlResourceParser;
-import android.view.inputmethod.EditorInfo;
-import android.inputmethodservice.Keyboard;
-
-public class TranslatorKeyboard extends Keyboard {
-
- private Key mEnterKey;
- private Key mSourceLanguageKey;
- private Key mTargetLanguageKey;
-
- static final int KEYCODE_PAGE_CHANGE = -10;
- static final int KEYCODE_SOURCE_LANGUAGE = -100;
- static final int KEYCODE_TARGET_LANGUAGE = -200;
- static final int MAX_LANGUAGE_KEYCODES = 99;
-
- private Translator mTranslator;
-
- public TranslatorKeyboard(Context context, int xmlLayoutResId, int modeId) {
- super(context, xmlLayoutResId, modeId);
-
- mTranslator = ((GFTranslator) context.getApplicationContext()).getTranslator();
- updateLanguageKeyLabels();
- }
-
- public void updateLanguageKeyLabels() {
- if (mSourceLanguageKey != null)
- mSourceLanguageKey.label = getLanguageKeyLabel(mTranslator.getSourceLanguage());
-
- if (mTargetLanguageKey != null)
- mTargetLanguageKey.label = getLanguageKeyLabel(mTranslator.getTargetLanguage());
- }
-
- public static String getLanguageKeyLabel(Language lang) {
- if ("cmn-hans-cn".equalsIgnoreCase(lang.getLangCode())) // this one has no ISO code
- return "chi";
- else
- return
- LocaleUtils.parseJavaLocale(lang.getLangCode(), Locale.getDefault())
- .getISO3Language();
- }
-
- @Override
- protected Key createKeyFromXml(Resources res, Row parent, int x, int y,
- XmlResourceParser parser) {
- Key key = new Key(res, parent, x, y, parser);
- if (key.codes[0] == 10) {
- mEnterKey = key;
- } else if (key.codes[0] == KEYCODE_SOURCE_LANGUAGE) {
- mSourceLanguageKey = key;
- } else if (key.codes[0] == KEYCODE_TARGET_LANGUAGE) {
- mTargetLanguageKey = key;
- }
- return key;
- }
-
- /**
- * This looks at the ime options given by the current editor, to set the
- * appropriate label on the keyboard's enter key (if it has one).
- */
- void setImeOptions(Resources res, int options) {
- if (mEnterKey == null) {
- return;
- }
-
- switch (options&(EditorInfo.IME_MASK_ACTION|EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
- case EditorInfo.IME_ACTION_DONE:
- mEnterKey.iconPreview = null;
- mEnterKey.icon = null;
- mEnterKey.label = res.getText(R.string.label_done_key);
- break;
- case EditorInfo.IME_ACTION_GO:
- mEnterKey.iconPreview = null;
- mEnterKey.icon = null;
- mEnterKey.label = res.getText(R.string.label_go_key);
- break;
- case EditorInfo.IME_ACTION_NEXT:
- mEnterKey.iconPreview = null;
- mEnterKey.icon = null;
- mEnterKey.label = res.getText(R.string.label_next_key);
- break;
- case EditorInfo.IME_ACTION_PREVIOUS:
- mEnterKey.iconPreview = null;
- mEnterKey.icon = null;
- mEnterKey.label = res.getText(R.string.label_previous_key);
- break;
- case EditorInfo.IME_ACTION_SEARCH:
- mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_search);
- mEnterKey.label = null;
- break;
- case EditorInfo.IME_ACTION_SEND:
- mEnterKey.iconPreview = null;
- mEnterKey.icon = null;
- mEnterKey.label = res.getText(R.string.label_send_key);
- break;
- default:
- mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_return);
- mEnterKey.label = null;
- break;
- }
- }
-}
\ No newline at end of file
diff --git a/src/ui/android/src/org/grammaticalframework/ui/android/TranslatorKeyboardView.java b/src/ui/android/src/org/grammaticalframework/ui/android/TranslatorKeyboardView.java
deleted file mode 100644
index 0a42eca2d..000000000
--- a/src/ui/android/src/org/grammaticalframework/ui/android/TranslatorKeyboardView.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package org.grammaticalframework.ui.android;
-
-import org.grammaticalframework.ui.android.TranslatorKeyboard;
-
-import android.content.Context;
-import android.graphics.Point;
-import android.inputmethodservice.Keyboard.Key;
-import android.inputmethodservice.KeyboardView;
-import android.util.AttributeSet;
-import android.view.Display;
-import android.view.Gravity;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.WindowManager;
-import android.widget.Button;
-import android.widget.PopupWindow;
-import android.widget.TableLayout;
-import android.widget.TableRow;
-
-public class TranslatorKeyboardView extends KeyboardView {
-
- private Translator mTranslator;
-
- public TranslatorKeyboardView(Context context, AttributeSet attrs) {
- super(context, attrs);
- mTranslator = ((GFTranslator) context.getApplicationContext()).getTranslator();
- }
-
- public TranslatorKeyboardView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- mTranslator = ((GFTranslator) context.getApplicationContext()).getTranslator();
- }
-
- private PopupWindow mLanguagesPopup = null;
- private Key mLanguagesKey = null;
-
- private void showLanguageOptions(Key popupKey) {
- if (mLanguagesPopup == null) {
- LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
- Context.LAYOUT_INFLATER_SERVICE);
- TableLayout popupContainer = (TableLayout)
- inflater.inflate(R.layout.keyboard_languages_options, null);
-
- int index = 0;
- TableRow row = null;
- for (Language lang : mTranslator.getAvailableLanguages()) {
- int col_index = index % 4;
- if (col_index == 0) {
- row = new TableRow(getContext());
- popupContainer.addView(row);
- }
-
- Button item = new Button(getContext());
- item.setText(TranslatorKeyboard.getLanguageKeyLabel(lang));
- item.setTag(index);
- item.setOnClickListener(this);
- row.addView(item, col_index);
- index++;
- }
-
- WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
- Display display = wm.getDefaultDisplay();
- Point size = new Point();
- display.getSize(size);
-
- popupContainer.measure(
- MeasureSpec.makeMeasureSpec(size.x, MeasureSpec.AT_MOST),
- MeasureSpec.makeMeasureSpec(size.y, MeasureSpec.AT_MOST));
-
- mLanguagesPopup = new PopupWindow(getContext());
- mLanguagesPopup.setWidth(popupContainer.getMeasuredWidth());
- mLanguagesPopup.setHeight(popupContainer.getMeasuredHeight());
- mLanguagesPopup.setContentView(popupContainer);
-
- int[] windowOffset = new int[2];
- getLocationInWindow(windowOffset);
- int popupX = popupKey.x + popupKey.width - popupContainer.getMeasuredWidth();
- int popupY = popupKey.y - popupContainer.getMeasuredHeight();
- final int x = popupX + popupContainer.getPaddingRight() + windowOffset[0];
- final int y = popupY + popupContainer.getPaddingBottom() + windowOffset[1];
- mLanguagesPopup.showAtLocation(this, Gravity.NO_GRAVITY, x, y);
-
- View closeButton = popupContainer.findViewById(R.id.closeButton);
- if (closeButton != null) closeButton.setOnClickListener(this);
- }
-
- mLanguagesKey = popupKey;
- }
-
- private void dismissLanguages() {
- if (mLanguagesPopup != null) {
- mLanguagesPopup.dismiss();
- mLanguagesPopup = null;
- mLanguagesKey = null;
- }
- }
-
- @Override
- public void onClick(View v) {
- super.onClick(v);
-
- if (v.getTag() != null) {
- if (mLanguagesKey.codes[0] == TranslatorKeyboard.KEYCODE_SOURCE_LANGUAGE ||
- mLanguagesKey.codes[0] == TranslatorKeyboard.KEYCODE_TARGET_LANGUAGE) {
- int keyCode = mLanguagesKey.codes[0] - ((Integer) v.getTag()) - 1;
- getOnKeyboardActionListener().onKey(keyCode, new int[] {keyCode});
- }
- }
-
- dismissLanguages();
- }
-
- public void closing() {
- super.closing();
- dismissLanguages();
- }
-
- @Override
- protected boolean onLongPress(Key key) {
- if (key.codes[0] == TranslatorKeyboard.KEYCODE_SOURCE_LANGUAGE ||
- key.codes[0] == TranslatorKeyboard.KEYCODE_TARGET_LANGUAGE) {
- showLanguageOptions(key);
- return true;
- } else {
- return super.onLongPress(key);
- }
- }
-}
diff --git a/src/ui/android/src/se/chalmers/phrasebook/backend/Model.java b/src/ui/android/src/se/chalmers/phrasebook/backend/Model.java
deleted file mode 100644
index 8e4b07b21..000000000
--- a/src/ui/android/src/se/chalmers/phrasebook/backend/Model.java
+++ /dev/null
@@ -1,206 +0,0 @@
-package se.chalmers.phrasebook.backend;
-
-import org.w3c.dom.*;
-import org.xml.sax.*;
-import org.w3c.dom.ls.*;
-
-import java.io.*;
-import java.util.*;
-import javax.xml.parsers.*;
-
-import org.grammaticalframework.pgf.Expr;
-import org.grammaticalframework.ui.android.R;
-import org.grammaticalframework.ui.android.GFTranslator;
-import se.chalmers.phrasebook.backend.syntax.*;
-
-public class Model {
- private static Model model;
-
- private List phrases;
- private Map> groups;
-
- private Model() {
- try {
- DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- InputStream is = GFTranslator.get().getAssets().open("phrases.xml");
- Document document = documentBuilder.parse(is);
- parseSentencesData(document);
- is.close();
- } catch (ParserConfigurationException e) {
- e.printStackTrace();
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- 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 List getSentences() {
- return phrases;
- }
-
- public List getGroup(String id) {
- return groups.get(id);
- }
-
- private void parseSentencesData(Document document) {
- phrases = new ArrayList();
- groups = new HashMap>();
- Map ids = new HashMap();
- List calls = new ArrayList();
-
- NodeList nodesList = document.getDocumentElement().getChildNodes();
- for (int i = 0; i < nodesList.getLength(); i++) {
- Node node = nodesList.item(i);
-
- if (node != null &&
- node.getNodeType() == Node.ELEMENT_NODE &&
- node.getNodeName().equals("sentence")) {
- NamedNodeMap attributes = node.getAttributes();
-
- if (attributes == null)
- continue;
-
- String desc = "";
- if (attributes.getNamedItem("desc") != null) {
- desc = attributes.getNamedItem("desc").getNodeValue();
- }
-
- SyntaxNode[] nodes = constructSyntaxNodeList(node, ids, calls);
- if (nodes.length > 0)
- phrases.add(new SyntaxTree(desc, nodes[0]));
- } else if (node != null &&
- node.getNodeType() == Node.ELEMENT_NODE &&
- node.getNodeName().equals("group")) {
-
- NamedNodeMap attributes = node.getAttributes();
- if (attributes == null)
- continue;
-
- String id = null;
- if (attributes.getNamedItem("id") != null) {
- id = attributes.getNamedItem("id").getNodeValue();
- }
- if (id == null)
- continue;
-
- List group_phrases = new ArrayList();
-
- NodeList nodesList2 = node.getChildNodes();
- for (int j = 0; j < nodesList2.getLength(); j++) {
- node = nodesList2.item(j);
-
- if (node != null &&
- node.getNodeType() == Node.ELEMENT_NODE &&
- node.getNodeName().equals("sentence")) {
- attributes = node.getAttributes();
-
- if (attributes == null)
- continue;
-
- String desc = "";
- if (attributes.getNamedItem("desc") != null) {
- desc = attributes.getNamedItem("desc").getNodeValue();
- }
-
- SyntaxNode[] nodes = constructSyntaxNodeList(node, ids, calls);
- if (nodes.length > 0) {
- SyntaxTree tree = new SyntaxTree(desc, nodes[0]);
- phrases.add(tree);
- group_phrases.add(tree);
- }
- }
- }
-
- groups.put(id, group_phrases);
- } else if (node.getAttributes() != null && node.getAttributes().getNamedItem("id") != null) {
- String id = node.getAttributes().getNamedItem("id").getNodeValue();
- SyntaxNode snode = constructSyntaxNode(node, ids, calls);
- if (snode == null) {
- throw new IllegalArgumentException(outerXml(node));
- }
- ids.put(id,snode);
- }
- }
-
- for (SyntaxNodeCall call : calls) {
- call.bind(ids);
- }
- }
-
- private SyntaxNode constructSyntaxNode(Node node, Map ids, List calls) {
- NamedNodeMap attributes = node.getAttributes();
- if (attributes == null)
- return null;
-
- String desc = "";
- if (attributes.getNamedItem("desc") != null) {
- desc = attributes.getNamedItem("desc").getNodeValue();
- }
-
- if (node.getNodeName().equals("function")) {
- String function = attributes.getNamedItem("name").getNodeValue();
- SyntaxNode[] arguments = constructSyntaxNodeList(node, ids, calls);
- return new SyntaxNodeFunction(desc, function, arguments);
- } else if (node.getNodeName().equals("numeral")) {
- return new SyntaxNodeNumeral(desc, 1, 100);
- } 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;
-
- String ref = attributes.getNamedItem("ref").getNodeValue();
- SyntaxNode[] arguments = constructSyntaxNodeList(node, ids, calls);
- SyntaxNodeCall call = new SyntaxNodeCall(desc, ref, arguments);
- calls.add(call);
- return call;
- } else if (node.getNodeName().equals("argument")) {
- int d = 0;
- if (attributes.getNamedItem("index") != null)
- d = Integer.parseInt(attributes.getNamedItem("index").getNodeValue());
- return new SyntaxNodeArgument(desc, d);
- }
-
- return null;
- }
-
- private SyntaxNode[] constructSyntaxNodeList(Node root, Map ids, List calls) {
- NodeList nl = root.getChildNodes();
-
- int index = 0;
- SyntaxNode[] list = new SyntaxNode[nl.getLength()];
- for (int i = 0; i < nl.getLength(); i++) {
- Node node = nl.item(i);
- if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
- list[index] = constructSyntaxNode(node, ids, calls);
- if (list[index] == null)
- throw new IllegalArgumentException(outerXml(node));
- index++;
- }
- }
- return Arrays.copyOf(list, index);
- }
-
- private String outerXml(Node node) {
- DOMImplementationLS lsImpl = (DOMImplementationLS)node.getOwnerDocument().getImplementation().getFeature("LS", "3.0");
- LSSerializer lsSerializer = lsImpl.createLSSerializer();
- lsSerializer.getDomConfig().setParameter("xml-declaration", false);
- return lsSerializer.writeToString(node);
- }
-}
-
diff --git a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/ChoiceContext.java b/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/ChoiceContext.java
deleted file mode 100644
index 3995ad063..000000000
--- a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/ChoiceContext.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package se.chalmers.phrasebook.backend.syntax;
-
-import java.util.*;
-
-public class ChoiceContext {
- private int pos;
- private List choices;
- private List stack;
-
- public ChoiceContext() {
- this.pos = pos;
- this.choices = new ArrayList();
- this.stack = new ArrayList();
- }
-
- public void reset() {
- pos = 0;
- stack.clear();
- }
-
- public void trim() {
- while (pos < choices.size())
- choices.remove(choices.size()-1);
- }
-
- public int choose(SyntaxNode node) {
- SyntacticChoice choice = null;
-
- if (pos < choices.size()) {
- if (choices.get(pos).getNode().unlink() == node.unlink()) {
- choice = choices.get(pos);
- } else {
- trim();
- }
- }
-
- if (choice == null) {
- choice = new SyntacticChoice(node);
- choices.add(choice);
- }
-
- pos++;
- return choice.getChoice();
- }
-
- public void push(SyntaxNode[] args) {
- stack.add(args);
- }
-
- public SyntaxNode[] pop() {
- return stack.remove(stack.size()-1);
- }
-
- public SyntaxNode getArgument(int i) {
- return stack.get(stack.size()-1)[i];
- }
-
- public List getChoices() {
- return choices;
- }
-}
diff --git a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntacticChoice.java b/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntacticChoice.java
deleted file mode 100644
index 709893504..000000000
--- a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntacticChoice.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package se.chalmers.phrasebook.backend.syntax;
-
-import java.io.*;
-
-public class SyntacticChoice implements Serializable {
- private int choice;
- private SyntaxNode node;
-
- public SyntacticChoice(SyntaxNode node) {
- this.node = node;
- this.choice = node.getDefaultChoice();
- }
-
- public SyntaxNode getNode() {
- return node;
- }
-
- public int getChoice() {
- return choice;
- }
-
- public void setChoice(int choice) {
- this.choice = choice;
- }
-}
diff --git a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNode.java b/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNode.java
deleted file mode 100644
index 5268e41d4..000000000
--- a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNode.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package se.chalmers.phrasebook.backend.syntax;
-
-import java.io.Serializable;
-import org.grammaticalframework.pgf.Expr;
-
-public class SyntaxNode implements Serializable {
- private String desc;
-
- public SyntaxNode(String desc) {
- this.desc = desc;
- }
-
- public String getDesc() {
- return desc;
- }
-
- public String getAbstractSyntax(ChoiceContext context) {
- return null;
- }
-
- public int getDefaultChoice() {
- return 0;
- }
-
- public SyntaxNode unlink() {
- return this;
- }
-
- @Override
- public String toString() {
- return desc;
- }
-}
diff --git a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeArgument.java b/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeArgument.java
deleted file mode 100644
index 12b13aa4b..000000000
--- a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeArgument.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package se.chalmers.phrasebook.backend.syntax;
-
-public class SyntaxNodeArgument extends SyntaxNode {
- private int index;
-
- public SyntaxNodeArgument(String desc, int index) {
- super(desc);
- this.index = index;
- }
-
- @Override
- public String getAbstractSyntax(ChoiceContext context) {
- return context.getArgument(index).getAbstractSyntax(context);
- }
-}
diff --git a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeBoolean.java b/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeBoolean.java
deleted file mode 100644
index da1e95e04..000000000
--- a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeBoolean.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package se.chalmers.phrasebook.backend.syntax;
-
-public class SyntaxNodeBoolean extends SyntaxNodeOption {
- public SyntaxNodeBoolean(String desc, SyntaxNode[] options) {
- super(desc,options);
- }
-}
diff --git a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeCall.java b/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeCall.java
deleted file mode 100644
index 199c818ae..000000000
--- a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeCall.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package se.chalmers.phrasebook.backend.syntax;
-
-import java.util.*;
-
-public class SyntaxNodeCall extends SyntaxNode {
- private String id;
- private SyntaxNode ref;
- private SyntaxNode[] arguments;
-
- public SyntaxNodeCall(String desc, String id, SyntaxNode[] arguments) {
- super(desc);
- this.id = id;
- this.ref = null;
- this.arguments = arguments;
- }
-
- public String getDesc() {
- String desc = super.getDesc();
- if (desc == null || desc.isEmpty())
- return ref.getDesc();
- return desc;
- }
-
- @Override
- public String getAbstractSyntax(ChoiceContext context) {
- context.push(arguments);
- String res = ref.getAbstractSyntax(context);
- context.pop();
- return res;
- }
-
- @Override
- public SyntaxNode unlink() {
- return ref.unlink();
- }
-
- public String getId() {
- return id;
- }
-
- public SyntaxNode getRef() {
- return ref;
- }
-
- public void bind(Map ids) {
- if (ref == null) {
- ref = ids.get(id);
- if (ref == null)
- throw new IllegalArgumentException("Missing reference to "+id);
- }
- }
-}
diff --git a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeFunction.java b/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeFunction.java
deleted file mode 100644
index 2bc6e187d..000000000
--- a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeFunction.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package se.chalmers.phrasebook.backend.syntax;
-
-import java.util.*;
-
-public class SyntaxNodeFunction extends SyntaxNode {
- private String function;
- private SyntaxNode[] arguments;
-
- public SyntaxNodeFunction(String desc, String function, SyntaxNode[] arguments) {
- super(desc);
- this.function = function;
- this.arguments = arguments;
- }
-
- public String getFunction() {
- return function;
- }
-
- public SyntaxNode[] getArguments() {
- return arguments;
- }
-
- @Override
- public String getAbstractSyntax(ChoiceContext context) {
- if (arguments == null || arguments.length == 0)
- return function;
-
- StringBuilder builder = new StringBuilder();
- builder.append(function);
- for (SyntaxNode argument : arguments) {
- builder.append(' ');
- builder.append('(');
- builder.append(argument.getAbstractSyntax(context));
- builder.append(')');
- }
-
- return builder.toString();
- }
-}
diff --git a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeNumeral.java b/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeNumeral.java
deleted file mode 100644
index 11a6b4103..000000000
--- a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeNumeral.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package se.chalmers.phrasebook.backend.syntax;
-
-public class SyntaxNodeNumeral extends SyntaxNode {
- private int min;
- private int max;
-
- public SyntaxNodeNumeral(String desc, int min, int max) {
- super(desc);
- this.min = min;
- this.max = max;
- }
-
- public String getAbstractSyntax(ChoiceContext context) {
- return nbrToSyntax(context.choose(this));
- }
-
- @Override
- public int getDefaultChoice() {
- return 1;
- }
-
- public int getMin() {
- return min;
- }
-
- public int getMax() {
- return max;
- }
-
- private String nbrToSyntax(int nbr) throws IllegalArgumentException {
- String syntax = "";
- if(nbr < 1000000 && nbr > 0) {
- if (nbr <=999) {
- syntax = "(num (pot2as3 " + subs1000(nbr) + "))";
- } else if(nbr % 1000 == 0) {
- syntax = "(num (pot3 " + subs1000(nbr/1000) + "))";
- } else if(nbr > 1000 && nbr%1000 != 0) {
- syntax = "(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;
- }
-}
diff --git a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeOption.java b/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeOption.java
deleted file mode 100644
index d7dc4ca83..000000000
--- a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxNodeOption.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package se.chalmers.phrasebook.backend.syntax;
-
-import java.util.*;
-import se.chalmers.phrasebook.backend.*;
-
-public class SyntaxNodeOption extends SyntaxNode {
- private SyntaxNode[] options;
-
- public SyntaxNodeOption(String desc, SyntaxNode[] options) {
- super(desc);
- this.options = options;
- }
-
- public SyntaxNode[] getOptions() {
- return options;
- }
-
- @Override
- public String getAbstractSyntax(ChoiceContext context) {
- return options[context.choose(this)].getAbstractSyntax(context);
- }
-}
diff --git a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxTree.java b/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxTree.java
deleted file mode 100644
index 964f07d0b..000000000
--- a/src/ui/android/src/se/chalmers/phrasebook/backend/syntax/SyntaxTree.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package se.chalmers.phrasebook.backend.syntax;
-
-import java.io.Serializable;
-import org.grammaticalframework.pgf.Expr;
-
-public class SyntaxTree implements Serializable {
- private String desc;
- private SyntaxNode root;
-
- public SyntaxTree(String desc, SyntaxNode root) {
- this.desc = desc;
- this.root = root;
- }
-
- public String getDesc() {
- return desc;
- }
-
- public SyntaxNode getRoot() {
- return root;
- }
-
- public Expr getAbstractSyntax(ChoiceContext choices) {
- Expr expr = Expr.readExpr(root.getAbstractSyntax(choices));
- choices.trim();
- return expr;
- }
-
- @Override
- public String toString() {
- return desc;
- }
-}
diff --git a/src/ui/android/src/se/chalmers/phrasebook/gui/activities/NavigationActivity.java b/src/ui/android/src/se/chalmers/phrasebook/gui/activities/NavigationActivity.java
deleted file mode 100644
index 1dc754380..000000000
--- a/src/ui/android/src/se/chalmers/phrasebook/gui/activities/NavigationActivity.java
+++ /dev/null
@@ -1,79 +0,0 @@
-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.*;
-import se.chalmers.phrasebook.gui.fragments.PhraseListFragment;
-import se.chalmers.phrasebook.gui.fragments.TranslatorFragment;
-
-public class NavigationActivity extends FragmentActivity {
-
- /**
- * Used to store the last screen title. For use in {@link #restoreActionBar()}.
- */
- private CharSequence mTitle;
- private Fragment mContent;
-
- 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();
- }
- }
-
- public void setToTranslationFragment(SyntaxTree phrase) {
- switchContent(TranslatorFragment.newInstance(phrase), "");
- }
-}
diff --git a/src/ui/android/src/se/chalmers/phrasebook/gui/fragments/PhraseListFragment.java b/src/ui/android/src/se/chalmers/phrasebook/gui/fragments/PhraseListFragment.java
deleted file mode 100644
index 7e3c09ada..000000000
--- a/src/ui/android/src/se/chalmers/phrasebook/gui/fragments/PhraseListFragment.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package se.chalmers.phrasebook.gui.fragments;
-
-import android.os.Bundle;
-
-import java.util.*;
-
-import android.app.Activity;
-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.activities.NavigationActivity;
-
-
-/**
- * Created by Björn on 2016-04-25.
- */
-public class PhraseListFragment extends Fragment {
-
- protected Model model;
- private String title;
- private String id;
-
- public static PhraseListFragment newInstance(String title) {
- PhraseListFragment fragment = new PhraseListFragment();
- Bundle args = new Bundle();
- args.putString("title", title);
- fragment.setArguments(args);
- return fragment;
- }
-
- public static PhraseListFragment newInstance(String title, String id) {
- PhraseListFragment fragment = new PhraseListFragment();
- Bundle args = new Bundle();
- args.putString("title", title);
- args.putString("id", id);
- fragment.setArguments(args);
- return fragment;
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- model = Model.getInstance();
- title = getArguments().getString("title");
- id = getArguments().getString("id");
- }
-
- @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);
-
- final List sentences = (id == null) ? model.getSentences() : model.getGroup(id);
- ArrayAdapter adapter = new ArrayAdapter(getActivity(), R.layout.phrase_list_item, sentences);
-
- 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 item_id) {
- SyntaxTree phrase = sentences.get(position);
- getActivity().getActionBar().setTitle(phrase.getDesc());
- ((NavigationActivity) getActivity()).setToTranslationFragment(phrase);
- }
- });
-
- return view;
- }
-}
diff --git a/src/ui/android/src/se/chalmers/phrasebook/gui/fragments/TranslatorFragment.java b/src/ui/android/src/se/chalmers/phrasebook/gui/fragments/TranslatorFragment.java
deleted file mode 100644
index cb5d50841..000000000
--- a/src/ui/android/src/se/chalmers/phrasebook/gui/fragments/TranslatorFragment.java
+++ /dev/null
@@ -1,253 +0,0 @@
-package se.chalmers.phrasebook.gui.fragments;
-
-import java.util.*;
-
-import android.os.Bundle;
-import android.content.Context;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentManager;
-import android.support.v4.app.FragmentTransaction;
-import android.view.*;
-import android.widget.*;
-import android.text.Editable;
-import android.text.TextWatcher;
-import android.text.method.PasswordTransformationMethod;
-
-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.*;
-import se.chalmers.phrasebook.backend.syntax.*;
-
-/**
- * Created by matilda on 04/04/16.
- */
-public class TranslatorFragment extends Fragment {
- protected Model model;
- Translator mTranslator;
- private TTS mTts;
-
- private TextView origin,target;
- private ListView list;
- SyntaxTree phrase;
-
- ChoiceContext mContext;
- ArrayAdapter mAdapter;
-
- public static TranslatorFragment newInstance(SyntaxTree phrase) {
- TranslatorFragment translatorFragment = new TranslatorFragment();
- Bundle args = new Bundle();
- args.putSerializable("phrase", phrase);
- translatorFragment.setArguments(args);
- return translatorFragment;
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- phrase = (SyntaxTree) getArguments().getSerializable("phrase");
- model = Model.getInstance();
- mTranslator = ((GFTranslator) getContext().getApplicationContext()).getTranslator();
- mTts = new TTS(getActivity());
- mContext = new ChoiceContext();
-
-
- mAdapter =
- new ArrayAdapter(getActivity(), R.layout.spinner_input_list_item, mContext.getChoices()) {
- LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-
- @Override
- public View getView (int position, View convertView, ViewGroup parent) {
- SyntacticChoice choice = mContext.getChoices().get(position);
- View view = null;
- 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);
- }
- return view;
- }
- };
- }
-
- @Override
- public View onCreateView(final LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.fragment_translator, container, false);
- origin = (TextView) view.findViewById(R.id.origin_phrase);
- target = (TextView) view.findViewById(R.id.target_phrase);
- list = (ListView) view.findViewById(R.id.input_holder);
- list.setAdapter(mAdapter);
-
- ImageView button = (ImageView) view.findViewById(R.id.button3);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- mTts.speak(mTranslator.getTargetLanguage().getLangCode(), (String) target.getText());
- }
- });
-
- updateSyntax();
- return view;
- }
-
- private View createSpinnerInputView(LayoutInflater inflater, final SyntacticChoice choice, final SyntaxNodeOption options, ViewGroup parent) {
- View view = inflater.inflate(R.layout.spinner_input_list_item, parent, false);
- TextView viewLabel = (TextView) view.findViewById(R.id.text_view_spinner);
- Spinner spinner = (Spinner) view.findViewById(R.id.choice_spinner);
-
- String label = options.getDesc();
- if (label == null || label.isEmpty()) {
- viewLabel.setVisibility(View.GONE);
- } else {
- viewLabel.setText(label);
- }
-
- final ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1,options.getOptions());
- adapter.setDropDownViewResource(android.R.layout.simple_list_item_1);
- spinner.setAdapter(adapter);
-
- spinner.setSelection(choice.getChoice());
- spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
-
- @Override
- public void onItemSelected(AdapterView> parent, View view, int position, long id) {
- if (position != choice.getChoice()) {
- choice.setChoice(position);
- updateSyntax();
- }
- }
-
- @Override
- public void onNothingSelected(AdapterView> parent) {
- }
- });
-
- return view;
- }
-
- private class NumericKeyBoardTransformationMethod extends PasswordTransformationMethod {
- @Override
- public CharSequence getTransformation(CharSequence source, View view) {
- return source;
- }
- }
-
- private View createNumeralInputView(LayoutInflater inflater, final SyntacticChoice choice, final SyntaxNodeNumeral numeral, ViewGroup parent) {
- View view = inflater.inflate(R.layout.number_input_list_item, parent, false);
- TextView viewLabel = (TextView) view.findViewById(R.id.textView_number);
- final SeekBar seekBar = (SeekBar) view.findViewById(R.id.seekBar);
- final EditText editNumber = (EditText) view.findViewById(R.id.editNumber);
-
- String label = choice.getNode().getDesc();
- if (label == null || label.isEmpty()) {
- viewLabel.setVisibility(View.GONE);
- } else {
- viewLabel.setText(label);
- }
-
- seekBar.setProgress(choice.getChoice());
- editNumber.setText(Integer.toString(choice.getChoice()));
-
- editNumber.setTransformationMethod(new NumericKeyBoardTransformationMethod());
- editNumber.requestFocus();
- seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- editNumber.setText(Integer.toString(progress+1));
- }
-
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
-
- }
-
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- }
- });
-
-
- 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) {
- int number;
- boolean update = false;
- try {
- if(editNumber.getText().toString().equals("")) {
- number = numeral.getMin();
- } else {
- number = Integer.parseInt(editNumber.getText().toString());
- if (number < numeral.getMin()) {
- number = numeral.getMin();
- update = true;
- }
- if (number > numeral.getMax()) {
- number = numeral.getMax();
- update = true;
- }
- editNumber.setInputType(0);
- }
- } catch (NumberFormatException e) {
- number = choice.getChoice();
- update = true;
- }
- choice.setChoice(number);
- if (update)
- editNumber.setText(Integer.toString(number));
- seekBar.setProgress(number-numeral.getMin());
- updateSyntax();
- }
- });
-
- 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();
-
- Expr expr = phrase.getAbstractSyntax(mContext);
- origin.setText(mTranslator.linearizeSource(expr));
- target.setText(mTranslator.linearize(expr));
- mAdapter.notifyDataSetChanged();
- }
-}
diff --git a/src/ui/android/topics.txt b/src/ui/android/topics.txt
deleted file mode 100644
index 785d07ba4..000000000
--- a/src/ui/android/topics.txt
+++ /dev/null
@@ -1,951 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-