├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── trash.png
│ │ │ │ ├── history_icon.png
│ │ │ │ ├── change_languages.png
│ │ │ │ ├── translate_icon.png
│ │ │ │ ├── default_favourites_icon.png
│ │ │ │ └── selected_favourites_icon.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── styles.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── strings.xml
│ │ │ ├── layout
│ │ │ │ ├── custom_action_bar.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── list_item.xml
│ │ │ │ ├── listview_fragment.xml
│ │ │ │ └── main_fragment.xml
│ │ │ ├── menu
│ │ │ │ └── bottom_navigation_menu.xml
│ │ │ ├── values-en
│ │ │ │ └── strings.xml
│ │ │ └── layout-land
│ │ │ │ ├── listview_fragment.xml
│ │ │ │ └── main_fragment.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── almaz
│ │ │ │ └── translator
│ │ │ │ ├── APIHelper.java
│ │ │ │ ├── TranslatedText.java
│ │ │ │ ├── Word.java
│ │ │ │ ├── Languages.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── CustomAdapter.java
│ │ │ │ ├── DataBaseHelper.java
│ │ │ │ ├── ListViewFragment.java
│ │ │ │ └── MainFragment.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── einepeople
│ │ │ └── translator
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── einepeople
│ │ └── translator
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── screenshot_1.jpg
├── screenshot_2.jpg
├── screenshot_3.jpg
├── screenshot_4.jpg
├── .idea
├── copyright
│ └── profiles_settings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/screenshot_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/screenshot_1.jpg
--------------------------------------------------------------------------------
/screenshot_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/screenshot_2.jpg
--------------------------------------------------------------------------------
/screenshot_3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/screenshot_3.jpg
--------------------------------------------------------------------------------
/screenshot_4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/screenshot_4.jpg
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/trash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/drawable/trash.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/history_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/drawable/history_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/change_languages.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/drawable/change_languages.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/translate_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/drawable/translate_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/default_favourites_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/drawable/default_favourites_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/selected_favourites_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AlmazSamatov/Translator-Android-app/HEAD/app/src/main/res/drawable/selected_favourites_icon.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Apr 24 18:22:29 MSK 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ffc400
4 | #ffd500
5 | #f7d200
6 | #000000
7 | #FFFFFF
8 | #D3D3D3
9 | #00000000
10 | #007ffd
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/custom_action_bar.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/einepeople/translator/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.einepeople.translator;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/almaz/translator/APIHelper.java:
--------------------------------------------------------------------------------
1 | package com.example.almaz.translator;
2 |
3 | import retrofit2.Call;
4 | import retrofit2.http.POST;
5 | import retrofit2.http.Query;
6 |
7 | /**
8 | * Created by almaz on 23.04.17.
9 | */
10 |
11 | public interface APIHelper {
12 |
13 | @POST("api/v1.5/tr.json/translate")
14 | Call getTranslation(@Query("key") String APIKey,
15 | @Query("text") String textToTranslate,
16 | @Query("lang") String lang);
17 | }
18 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## About project:
2 | Mobile Android app for text translating, which uses Yandex Translator API.
3 |
4 | ## Application description:
5 | * Java, Retrofit 2 (To work with network), RxJava, Sqlite (To store words in history and favorites)
6 | * Automatically translates after 0.5 seconds after typing. Implemented via RxJava
7 | * Supports 90 languages
8 | * Automatically saves text to history
9 | * User can add translation to favourites
10 | * Interface translated to Russian and English languages and selected automatically from settings of smartphone
11 |
12 | ## Screenshots:
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/bottom_navigation_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
10 |
16 |
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/einepeople/translator/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.einepeople.translator;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.einepeople.translator", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/almaz/translator/TranslatedText.java:
--------------------------------------------------------------------------------
1 | package com.example.almaz.translator;
2 |
3 | import java.util.List;
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class TranslatedText {
8 |
9 | @SerializedName("code")
10 | @Expose
11 | private Integer code;
12 | @SerializedName("lang")
13 | @Expose
14 | private String lang;
15 | @SerializedName("text")
16 | @Expose
17 | private List text = null;
18 |
19 | public Integer getCode() {
20 | return code;
21 | }
22 |
23 | public void setCode(Integer code) {
24 | this.code = code;
25 | }
26 |
27 | public String getLang() {
28 | return lang;
29 | }
30 |
31 | public void setLang(String lang) {
32 | this.lang = lang;
33 | }
34 |
35 | public List getText() {
36 | return text;
37 | }
38 |
39 | public void setText(List text) {
40 | this.text = text;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\einepeople\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
16 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Переводчик
3 | Русский
4 | Английский
5 | Ошибка
6 | Перевод
7 | Избранное
8 | История
9 | Вы уверены, что хотите очистить избранное?
10 | Вы уверены, что хотите очистить историю?
11 | Найти в истории
12 | Найти в избранном
13 | Нет переводов в избранном
14 | Нет переводов в истории
15 | Введите слово или текст
16 | Переведено сервисом «Яндекс.Переводчик»
17 | http://translate.yandex.ru/
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values-en/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Translation
4 | Translated via "Yandex Translator" service
5 | Are you sure that you want to clear favourites?
6 | Are you sure that you want to clear history?
7 | Find in favourites
8 | Find in history
9 | No translations in favourites
10 | No translations in history
11 | Error
12 | Russian
13 | English
14 | Favourites
15 | History
16 | Enter word or text
17 | Translator
18 | http://translate.yandex.ru/
19 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.example.einepeople.translator"
8 | minSdkVersion 19
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | jackOptions{
14 | enabled true
15 | }
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | compileOptions {
24 | targetCompatibility JavaVersion.VERSION_1_8
25 | sourceCompatibility JavaVersion.VERSION_1_8
26 | }
27 | }
28 |
29 | dependencies {
30 | compile fileTree(dir: 'libs', include: ['*.jar'])
31 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
32 | exclude group: 'com.android.support', module: 'support-annotations'
33 | })
34 | compile 'com.android.support:appcompat-v7:25.3.1'
35 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
36 | testCompile 'junit:junit:4.12'
37 | compile 'com.android.support:design:25.3.1'
38 | compile 'com.squareup.retrofit2:retrofit:2.2.0'
39 | compile 'com.squareup.retrofit2:converter-gson:2.2.0'
40 | compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
19 |
20 |
24 |
25 |
33 |
34 |
41 |
42 |
43 |
44 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/listview_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
25 |
26 |
33 |
34 |
44 |
45 |
55 |
56 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-land/listview_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
25 |
26 |
33 |
34 |
44 |
45 |
55 |
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/almaz/translator/Word.java:
--------------------------------------------------------------------------------
1 | package com.example.almaz.translator;
2 |
3 | import java.util.Locale;
4 |
5 | /**
6 | * Created by almaz on 12.04.17.
7 | */
8 |
9 | public class Word {
10 | private String word;
11 | private int sourcePosition = -1;
12 | private int targetPosition = -1;
13 | private String sourceLanguage;
14 | private String targetLanguage;
15 | private String translation;
16 |
17 | Word(String word, String translation, int sourcePosition, int targetPosition) {
18 | this.word = word;
19 | this.translation = translation;
20 | this.sourcePosition = sourcePosition;
21 | this.targetPosition = targetPosition;
22 | if(Locale.getDefault().getLanguage().equals("en")) {
23 | sourceLanguage = Languages.getLangCodeEN(sourcePosition).toUpperCase();
24 | targetLanguage = Languages.getLangCodeEN(targetPosition).toUpperCase();
25 | } else{
26 | sourceLanguage = Languages.getLangCodeRU(sourcePosition).toUpperCase();
27 | targetLanguage = Languages.getLangCodeRU(targetPosition).toUpperCase();
28 | }
29 | }
30 |
31 | public String getWord() {
32 | return word;
33 | }
34 |
35 | public void setWord(String word) {
36 | this.word = word;
37 | }
38 |
39 | public void setTranslation(String translation) {
40 | this.translation = translation;
41 | }
42 |
43 | public String getTranslation() {
44 | return translation;
45 | }
46 |
47 | public int getSourcePosition() {
48 | return sourcePosition;
49 | }
50 |
51 | public void setSourcePosition(int sourcePosition) {
52 | this.sourcePosition = sourcePosition;
53 | }
54 |
55 | public String getSourceLanguage() {
56 | return sourceLanguage;
57 | }
58 |
59 | public String getTargetLanguage() {
60 | return targetLanguage;
61 | }
62 |
63 | public int getTargetPosition() {
64 | return targetPosition;
65 | }
66 |
67 | public void setTargetPosition(int targetPosition) {
68 | this.targetPosition = targetPosition;
69 | }
70 |
71 | public boolean isEmpty() {
72 | if (word == null && targetPosition == -1 && sourcePosition == -1)
73 | return true;
74 | else
75 | return false;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/almaz/translator/Languages.java:
--------------------------------------------------------------------------------
1 | package com.example.almaz.translator;
2 |
3 | public class Languages{
4 |
5 | private static String[] langsRU = {"Азербайджанский", "Албанский", "Амхарский", "Английский", "Арабский", "Армянский", "Африкаанс", "Баскский", "Башкирский", "Белорусский", "Бенгальский", "Болгарский", "Боснийский", "Валлийский", "Венгерский", "Вьетнамский", "Гаитянский (креольский)", "Галисийский", "Голландский", "Горномарийский", "Греческий", "Грузинский", "Гуджарати", "Датский", "Иврит", "Идиш", "Индонезийский", "Ирландский", "Итальянский", "Исландский", "Испанский", "Казахский", "Каннада", "Каталанский", "Киргизский", "Китайский", "Корейский", "Коса", "Латынь", "Латышский", "Литовский", "Люксембургский", "Малагасийский", "Малайский", "Малаялам", "Мальтийский", "Македонский", "Маори", "Маратхи", "Марийский", "Монгольский", "Немецкий", "Непальский", "Норвежский", "Панджаби", "Папьяменто", "Персидский", "Польский", "Португальский", "Румынский", "Русский", "Себуанский", "Сербский", "Сингальский", "Словацкий", "Словенский", "Суахили", "Сунданский", "Таджикский", "Тайский", "Тагальский", "Тамильский", "Татарский", "Телугу", "Турецкий", "Удмуртский", "Узбекский", "Украинский", "Урду", "Финский", "Французский", "Хинди", "Хорватский", "Чешский", "Шведский", "Шотландский", "Эстонский", "Эсперанто", "Яванский", "Японский"};
6 | private static String[] langCodesRU = {"az", "sq", "am", "en", "ar", "hy", "af", "eu", "ba", "be", "bn", "bg", "bs", "cy", "hu", "vi", "ht", "gl", "nl", "mrj", "el", "ka", "gu", "da", "he", "yi", "id", "ga", "it", "is", "es", "kk", "kn", "ca", "ky", "zh", "ko", "xh", "la", "lv", "lt", "lb", "mg", "ms", "ml", "mt", "mk", "mi", "mr", "mhr", "mn", "de", "ne", "no", "pa", "pap", "fa", "pl", "pt", "ro", "ru", "ceb", "sr", "si", "sk", "sl", "sw", "su", "tg", "th", "tl", "ta", "tt", "te", "tr", "udm", "uz", "uk", "ur", "fi", "fr", "hi", "hr", "cs", "sv", "gd", "et", "eo", "jv", "ja"};
7 |
8 | private static String[] langsEN = {"Afrikaans", "Albanian", "Amharic", "Arabic", "Armenian", "Azerbaijan", "Bashkir", "Basque", "Belarussian", "Bengali", "Bosnian", "Bulgarian", "Catalan", "Cebuano", "Chinese", "Croatian", "Czech", "Danish", "Dutch", "English", "Esperanto", "Estonian", "Finnish", "French", "Galician", "Georgian", "German", "Greek", "Gujarati", "Haitian", "Hebrew", "Hindi", "Hungarian", "Icelandic", "Indonesian", "Irish", "Italian", "Japanese", "Javanese", "Kannada", "Kazakh", "Korean", "Kyrgyz", "Latin", "Latvian", "Lithuanian", "Luxembourg", "Macedonian", "Malagasy", "Malay", "Malayalam", "Maltese", "Maori", "Marathi", "Mari", "Mari", "Mongolian", "Nepali", "Norwegian", "Papiamento", "Persian", "Polish", "Portuguese", "Punjabi", "Romanian", "Russian", "Scottish", "Serbian", "Sinhala", "Slovak", "Slovenian", "Spanish", "Spit", "Sundanese", "Swahili", "Swedish", "Tagalog", "Tajik", "Tamil", "Tatar", "Telugu", "Thai", "Turkish", "Udmurt", "Ukrainian", "Urdu", "Uzbek", "Vietnamese", "Welsh", "Yiddish"};
9 | private static String[] langCodesEN = {"af", "sq", "am", "ar", "hy", "az", "ba", "eu", "be", "bn", "bs", "bg", "ca", "ceb", "zh", "hr", "cs", "da", "nl", "en", "eo", "et", "fi", "fr", "gl", "ka", "de", "el", "gu", "ht", "he", "hi", "hu", "is", "id", "ga", "it", "ja", "jv", "kn", "kk", "ko", "ky", "la", "lv", "lt", "lb", "mk", "mg", "ms", "ml", "mt", "mi", "mr", "mhr", "mrj", "mn", "ne", "no", "pap", "fa", "pl", "pt", "pa", "ro", "ru", "gd", "sr", "si", "sk", "sl", "es", "xh", "su", "sw", "sv", "tl", "tg", "ta", "tt", "te", "th", "tr", "udm", "uk", "ur", "uz", "vi", "cy", "yi"};
10 |
11 | public static String[] getLangsRU(){
12 | return langsRU;
13 | }
14 |
15 | public static String[] getLangsEN(){
16 | return langsEN;
17 | }
18 |
19 | public static String getLangCodeRU(int i){
20 | return langCodesRU[i];
21 | }
22 |
23 | public static String getLangCodeEN(int i){
24 | return langCodesEN[i];
25 | }
26 | };
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/main_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
30 |
31 |
40 |
41 |
57 |
58 |
69 |
70 |
81 |
82 |
92 |
93 |
103 |
104 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-land/main_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
30 |
31 |
40 |
41 |
58 |
59 |
71 |
72 |
83 |
84 |
95 |
96 |
107 |
108 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/almaz/translator/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.almaz.translator;
2 |
3 | import android.content.Context;
4 | import android.content.DialogInterface;
5 | import android.os.Bundle;
6 | import android.support.annotation.NonNull;
7 | import android.support.design.widget.BottomNavigationView;
8 | import android.support.v4.app.FragmentTransaction;
9 | import android.support.v7.app.AlertDialog;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.view.MenuItem;
12 | import android.view.View;
13 | import android.view.WindowManager;
14 |
15 | public class MainActivity extends AppCompatActivity {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 |
22 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
23 | if(savedInstanceState == null){
24 | changeToMainView();
25 | }
26 | bottomNavigationListener();
27 | }
28 |
29 | public void bottomNavigationListener() {
30 | BottomNavigationView bottomNavigationView = (BottomNavigationView)
31 | findViewById(R.id.bottom_navigation);
32 |
33 | bottomNavigationView.setOnNavigationItemSelectedListener(
34 | new BottomNavigationView.OnNavigationItemSelectedListener() {
35 | @Override
36 | public boolean onNavigationItemSelected(@NonNull MenuItem item) {
37 | switch (item.getItemId()) {
38 | case R.id.action_translate:
39 | changeToMainView();
40 | break;
41 | case R.id.action_favourites:
42 | changeToListView("Favourites.db");
43 | break;
44 | case R.id.action_history:
45 | changeToListView("History.db");
46 | break;
47 | }
48 | return true;
49 | }
50 | });
51 | }
52 |
53 | public void changeToListView(String nameOfDB) {
54 | // Change current fragment in activity
55 | FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
56 | ListViewFragment listViewFragment = new ListViewFragment().newInstance(nameOfDB);
57 | ft.replace(R.id.fragment, listViewFragment);
58 | ft.commit();
59 | }
60 |
61 | public void changeToMainView() {
62 | // Change current fragment in activity
63 | FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
64 | ft.replace(R.id.fragment, new MainFragment());
65 | ft.commit();
66 | }
67 |
68 | public void TrashOnClick(View v) {
69 | String title = getSupportActionBar().getTitle().toString();
70 | if (title.equals(getString(R.string.text_history))) {
71 | showConfirmationDialog(R.string.delete_confirmation_of_history_words, "History.db",
72 | v.getContext());
73 | } else {
74 | showConfirmationDialog(R.string.delete_confirmation_of_favourite_words, "Favourites.db",
75 | v.getContext());
76 | }
77 | }
78 |
79 | public void showConfirmationDialog(int answerID, final String nameOfDB, final Context context) {
80 | int title = R.string.text_history;
81 | if (nameOfDB.equals("Favourites.db")) {
82 | title = R.string.text_favourites;
83 | }
84 | new AlertDialog.Builder(context)
85 | .setTitle(title)
86 | .setMessage(answerID)
87 | .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
88 | // if user agrees to delete words, then delete
89 | public void onClick(DialogInterface dialog, int whichButton) {
90 | deleteWordsFromDB(context, nameOfDB);
91 | changeToListView(nameOfDB);
92 | }
93 | })
94 | .setNegativeButton(android.R.string.no, null).show();
95 | }
96 |
97 | public void deleteWordsFromDB(Context context, String nameOfDB) {
98 | DataBaseHelper dataBaseHelper = new DataBaseHelper(context, nameOfDB);
99 | dataBaseHelper.deleteAllWords();
100 | dataBaseHelper.close();
101 | }
102 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/almaz/translator/CustomAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.almaz.translator;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.LayoutRes;
5 | import android.support.annotation.NonNull;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ArrayAdapter;
10 | import android.widget.Filter;
11 | import android.widget.ImageButton;
12 | import android.widget.TextView;
13 |
14 | import org.w3c.dom.Text;
15 |
16 | import java.util.ArrayList;
17 |
18 | /**
19 | * Created by almaz on 12.04.17.
20 | */
21 |
22 | public class CustomAdapter extends ArrayAdapter {
23 |
24 | private ArrayList originalItems;
25 | private ArrayList filteredItems;
26 | private LayoutInflater inflater;
27 |
28 | public CustomAdapter(@NonNull Context context, @LayoutRes int resource,
29 | @NonNull ArrayList objects) {
30 | super(context, resource, objects);
31 | this.originalItems = objects;
32 | filteredItems = new ArrayList();
33 | filteredItems.addAll(this.originalItems);
34 | inflater = LayoutInflater.from(context);
35 | }
36 |
37 | public int getCount() {
38 | return filteredItems.size();
39 | }
40 |
41 | public Word getItem(int position) {
42 | return filteredItems.get(position);
43 | }
44 |
45 | public long getItemId(int position) {
46 | return position;
47 | }
48 |
49 | @NonNull
50 | @Override
51 | public Filter getFilter() {
52 | Filter filter = new Filter() {
53 |
54 | @Override
55 | protected FilterResults performFiltering(CharSequence constraint) {
56 | FilterResults results = new FilterResults();
57 | final ArrayList filteredList = new ArrayList();
58 |
59 | if (constraint.equals("") || constraint.toString().trim().length() == 0) {
60 | results.values = originalItems;
61 | } else {
62 | String textToFilter = constraint.toString().toLowerCase();
63 | for (Word word : originalItems) {
64 | if (word.getWord().length() >= textToFilter.length() &&
65 | word.getWord().toLowerCase().contains(textToFilter)) {
66 | filteredList.add(word);
67 | }
68 | }
69 | results.values = filteredList;
70 | }
71 | return results;
72 | }
73 |
74 | @Override
75 | protected void publishResults(CharSequence constraint, FilterResults results) {
76 | if (results.values != null) {
77 | filteredItems = (ArrayList) results.values;
78 | notifyDataSetChanged();
79 | }
80 | }
81 | };
82 | return filter;
83 | }
84 |
85 | public View getView(int position, View convertView, ViewGroup parent) {
86 | final Word item = filteredItems.get(position);
87 | View v = null;
88 |
89 | if (convertView == null) {
90 | v = inflater.inflate(R.layout.list_item, parent, false);
91 | } else {
92 | v = convertView;
93 | }
94 |
95 | ImageButton button = (ImageButton) v.findViewById(R.id.addToFavourites2);
96 | TextView text = (TextView) v.findViewById(R.id.text);
97 | TextView translation = (TextView) v.findViewById(R.id.translation);
98 | final TextView language = (TextView) v.findViewById(R.id.languages);
99 |
100 | text.setText(item.getWord());
101 | translation.setText(item.getTranslation());
102 | language.setText(item.getSourceLanguage() + "-" +
103 | item.getTargetLanguage());
104 |
105 | DataBaseHelper dbhelper = new DataBaseHelper(v.getContext(), "Favourites.db");
106 | if (dbhelper.isInDataBase(item)) {
107 | button.setImageResource(R.drawable.selected_favourites_icon);
108 | }
109 | dbhelper.close();
110 |
111 | button.setOnClickListener(
112 | new View.OnClickListener() {
113 | public void onClick(View v) {
114 |
115 | String text = item.getWord();
116 | String translation = item.getTranslation();
117 | int[] languages = {item.getSourcePosition(), item.getTargetPosition()};
118 | ImageButton button = (ImageButton) v.findViewById(R.id.addToFavourites2);
119 | Word word = new Word(text, translation, languages[0], languages[1]);
120 |
121 | DataBaseHelper dbhelper = new DataBaseHelper(getContext(), "Favourites.db");
122 | if (dbhelper.isInDataBase(word)) {
123 | dbhelper.setDeleted(word);
124 | button.setImageResource(R.drawable.default_favourites_icon);
125 | } else {
126 | dbhelper.insertWord(word);
127 | button.setImageResource(R.drawable.selected_favourites_icon);
128 | }
129 | dbhelper.close();
130 |
131 | }
132 | });
133 |
134 | return v;
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/almaz/translator/DataBaseHelper.java:
--------------------------------------------------------------------------------
1 | package com.example.almaz.translator;
2 |
3 | import android.content.ContentValues;
4 | import android.content.Context;
5 | import android.database.Cursor;
6 | import android.database.DatabaseUtils;
7 | import android.database.sqlite.SQLiteDatabase;
8 | import android.database.sqlite.SQLiteOpenHelper;
9 |
10 | import java.util.ArrayList;
11 |
12 | public class DataBaseHelper extends SQLiteOpenHelper {
13 |
14 | public DataBaseHelper(Context context, String name) {
15 | super(context, name, null, 1);
16 | }
17 |
18 | @Override
19 | public void onCreate(SQLiteDatabase db) {
20 | db.execSQL("CREATE TABLE words (word TEXT, translation TEXT, isDeleted INTEGER, " +
21 | "sourcePosition INTEGER, targetPosition INTEGER, sourceLanguage TEXT, " +
22 | "targetLanguage TEXT)");
23 | }
24 |
25 | @Override
26 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
27 | db.execSQL("DROP TABLE IF EXISTS words");
28 | onCreate(db);
29 | }
30 |
31 | public void insertWord(Word item) {
32 | if (!isInDataBase(item)) {
33 | SQLiteDatabase db = this.getWritableDatabase();
34 | ContentValues contentValues = new ContentValues();
35 | contentValues.put("word", item.getWord());
36 | contentValues.put("translation", item.getTranslation());
37 | contentValues.put("isDeleted", 0);
38 | contentValues.put("sourcePosition", item.getSourcePosition());
39 | contentValues.put("targetPosition", item.getTargetPosition());
40 | contentValues.put("sourceLanguage", item.getSourceLanguage());
41 | contentValues.put("targetLanguage", item.getTargetLanguage());
42 | db.insert("words", null, contentValues);
43 | }
44 | }
45 |
46 | public int[] getLanguages(String word, String sourceLanguage, String targetLanguage) {
47 | int[] languages = new int[2];
48 | long count = DatabaseUtils.queryNumEntries(this.getReadableDatabase(), "words",
49 | "word = ? ", new String[]{word});
50 | System.out.print(String.valueOf(count));
51 | SQLiteDatabase db = this.getReadableDatabase();
52 | Cursor cursor = db.rawQuery("SELECT sourcePosition, targetPosition FROM words WHERE " +
53 | " word = '" + word + "' AND sourceLanguage = '" + sourceLanguage + "' AND " +
54 | "targetLanguage = '" + targetLanguage + "'", null);
55 |
56 | cursor.moveToFirst();
57 |
58 | languages[0] = cursor.getInt(cursor.getColumnIndex("sourcePosition"));
59 | languages[1] = cursor.getInt(cursor.getColumnIndex("targetPosition"));
60 |
61 | return languages;
62 | }
63 |
64 | public void setDeleted(Word item) {
65 | SQLiteDatabase db = this.getWritableDatabase();
66 | ContentValues contentValues = new ContentValues();
67 | contentValues.put("word", item.getWord());
68 | contentValues.put("translation", item.getTranslation());
69 | contentValues.put("isDeleted", 1);
70 | contentValues.put("sourcePosition", item.getSourcePosition());
71 | contentValues.put("targetPosition", item.getTargetPosition());
72 | contentValues.put("sourceLanguage", item.getSourceLanguage());
73 | contentValues.put("targetLanguage", item.getTargetLanguage());
74 | db.update("words", contentValues, "word = ? AND sourcePosition = ? AND targetPosition = ?",
75 | new String[]{item.getWord(), String.valueOf(item.getSourcePosition()),
76 | String.valueOf(item.getTargetPosition())});
77 | }
78 |
79 | public void deleteWord(Word item){
80 | SQLiteDatabase db = this.getWritableDatabase();
81 | db.delete("words", "isDeleted = ? AND word = ? AND sourcePosition = ? AND targetPosition = ?",
82 | new String[]{"0", item.getWord(), String.valueOf(item.getSourcePosition()),
83 | String.valueOf(item.getTargetPosition())});
84 | }
85 |
86 | public void deleteAllWords() {
87 | SQLiteDatabase db = this.getWritableDatabase();
88 | db.execSQL("DELETE FROM words");
89 | }
90 |
91 | public boolean isInDataBase(Word word) {
92 | long count = DatabaseUtils.queryNumEntries(this.getReadableDatabase(), "words",
93 | "word = ? AND sourcePosition = ? AND targetPosition = ? AND isDeleted = ?",
94 | new String[]{word.getWord(), String.valueOf(word.getSourcePosition()),
95 | String.valueOf(word.getTargetPosition()), "0"});
96 | if (count == 0)
97 | return false;
98 | else
99 | return true;
100 | }
101 |
102 | public ArrayList getAllWords() {
103 | ArrayList arrayList = new ArrayList();
104 | SQLiteDatabase db = this.getWritableDatabase();
105 | db.delete("words", "isDeleted = ?", new String[]{String.valueOf(1)});
106 |
107 | db = this.getReadableDatabase();
108 | Cursor cursor = db.rawQuery("SELECT word, translation, sourcePosition, targetPosition FROM words", null);
109 |
110 | cursor.moveToFirst();
111 |
112 | while (!cursor.isAfterLast()) {
113 | Word item = new Word(cursor.getString(cursor.getColumnIndex("word")),
114 | cursor.getString(cursor.getColumnIndex("translation")),
115 | cursor.getInt(cursor.getColumnIndex("sourcePosition")),
116 | cursor.getInt(cursor.getColumnIndex("targetPosition")));
117 | if (!item.isEmpty()) {
118 | arrayList.add(item);
119 | }
120 | cursor.moveToNext();
121 | }
122 |
123 | return arrayList;
124 | }
125 |
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/almaz/translator/ListViewFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.almaz.translator;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v7.app.ActionBar;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.text.Editable;
11 | import android.text.TextWatcher;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.AdapterView;
16 | import android.widget.EditText;
17 | import android.widget.ListView;
18 | import android.widget.TextView;
19 |
20 | import java.util.ArrayList;
21 |
22 | /**
23 | * Created by almaz on 16.04.17.
24 | */
25 |
26 | public class ListViewFragment extends Fragment {
27 |
28 | private ActionBar actionBar;
29 | private CustomAdapter adapter;
30 | private String nameOfDB;
31 | private View rootView;
32 | private TextView apiInfo;
33 | private TextView link;
34 |
35 | public static ListViewFragment newInstance(String nameOfDB) {
36 | ListViewFragment listViewFragment = new ListViewFragment();
37 | Bundle args = new Bundle();
38 | args.putString("nameOfDB", nameOfDB);
39 | listViewFragment.setArguments(args);
40 | return listViewFragment;
41 | }
42 |
43 | @Override
44 | public void onCreate(@Nullable Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | nameOfDB = getArguments().getString("nameOfDB");
47 | actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
48 | }
49 |
50 | @Nullable
51 | @Override
52 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
53 | Bundle savedInstanceState) {
54 | rootView = inflater.inflate(R.layout.listview_fragment, container, false);
55 | link = (TextView) rootView.findViewById(R.id.link);
56 | apiInfo = (TextView) rootView.findViewById(R.id.api_info);
57 | changeToListView();
58 | setHintToSearch();
59 | return rootView;
60 | }
61 |
62 | public void setHintToSearch() {
63 | EditText search = (EditText) rootView.findViewById(R.id.search);
64 | if (nameOfDB.equals("History.db")) {
65 | search.setHint(R.string.history_search_hint);
66 | } else {
67 | search.setHint(R.string.favourite_search_hint);
68 | }
69 | }
70 |
71 | public void setCustomActionBar() {
72 | actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
73 | actionBar.setCustomView(R.layout.custom_action_bar);
74 |
75 | if (nameOfDB.equals("History.db")) {
76 | actionBar.setTitle(R.string.text_history);
77 | } else {
78 | actionBar.setTitle(R.string.text_favourites);
79 | }
80 | }
81 |
82 | public void changeToListView() {
83 | final DataBaseHelper dataBaseHelper = new DataBaseHelper(getContext(), nameOfDB);
84 | ArrayList arrayList = dataBaseHelper.getAllWords();
85 | adapter = new CustomAdapter(getContext(), R.layout.list_item, arrayList);
86 |
87 | if (arrayList.isEmpty()) {
88 | TextView noWordsText = (TextView) rootView.findViewById(R.id.no_words_in_listview);
89 | EditText search = (EditText) rootView.findViewById(R.id.search);
90 | noWordsText.setVisibility(View.VISIBLE);
91 | search.setVisibility(View.INVISIBLE);
92 | actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);
93 | if (nameOfDB.equals("History.db")) {
94 | noWordsText.setText(R.string.no_words_in_history);
95 | actionBar.setTitle(R.string.text_history);
96 | } else {
97 | noWordsText.setText(R.string.no_words_in_favourites);
98 | actionBar.setTitle(R.string.text_favourites);
99 | }
100 | } else {
101 | setCustomActionBar();
102 | apiInfo.setVisibility(View.VISIBLE);
103 | link.setVisibility(View.VISIBLE);
104 |
105 | ListView listView = (ListView) rootView.findViewById(R.id.listView);
106 | listView.setAdapter(adapter);
107 |
108 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
109 | @Override
110 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
111 | TextView text = (TextView) view.findViewById(R.id.text);
112 | TextView translation = (TextView) view.findViewById(R.id.translation);
113 | TextView textView = (TextView) view.findViewById(R.id.languages);
114 | String[] langs = String.valueOf(textView.getText()).split("-");
115 |
116 | DataBaseHelper dbhelper = new DataBaseHelper(view.getContext(), nameOfDB);
117 | int[] languages = dbhelper.getLanguages(String.valueOf(text.getText()), langs[0],
118 | langs[1]);
119 | dbhelper.close();
120 |
121 | dbhelper = new DataBaseHelper(view.getContext(), "Favourites.db");
122 | SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
123 | SharedPreferences.Editor editor = sharedPref.edit();
124 | editor.putInt("selection1", languages[0]);
125 | editor.putInt("selection2", languages[1]);
126 | editor.putString("textToTranslate", text.getText().toString());
127 | editor.putString("translatedText", translation.getText().toString());
128 | if(dbhelper.isInDataBase(new Word(text.getText().toString(),
129 | translation.getText().toString(), languages[0], languages[1]))){
130 | editor.putBoolean("isFavourite", true);
131 | } else{
132 | editor.putBoolean("isFavourite", false);
133 | }
134 | editor.apply();
135 | dbhelper.close();
136 |
137 | ((MainActivity) getActivity()).changeToMainView();
138 | }
139 | });
140 |
141 | EditText search = (EditText) rootView.findViewById(R.id.search);
142 | search.addTextChangedListener(new TextWatcher() {
143 | @Override
144 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
145 |
146 | @Override
147 | public void onTextChanged(CharSequence s, int start, int before, int count) {}
148 |
149 | @Override
150 | public void afterTextChanged(Editable s) {
151 | adapter.getFilter().filter(s.toString());
152 | }
153 | });
154 | }
155 |
156 | }
157 |
158 | @Override
159 | public void onDestroy() {
160 | actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);
161 | actionBar.setTitle(R.string.app_name);
162 | super.onDestroy();
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/almaz/translator/MainFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.almaz.translator;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.os.Bundle;
6 | import android.preference.PreferenceManager;
7 | import android.support.annotation.Nullable;
8 | import android.support.v4.app.Fragment;
9 | import android.text.method.ScrollingMovementMethod;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.ArrayAdapter;
14 | import android.widget.EditText;
15 | import android.widget.ImageButton;
16 | import android.widget.Spinner;
17 | import android.widget.TextView;
18 |
19 | import com.jakewharton.rxbinding.view.RxView;
20 | import com.jakewharton.rxbinding.widget.RxTextView;
21 |
22 | import java.util.ArrayList;
23 | import java.util.Collections;
24 | import java.util.List;
25 | import java.util.Locale;
26 | import java.util.concurrent.TimeUnit;
27 |
28 | import retrofit2.Call;
29 | import retrofit2.Callback;
30 | import retrofit2.Response;
31 | import retrofit2.Retrofit;
32 | import retrofit2.converter.gson.GsonConverterFactory;
33 | import rx.functions.Action1;
34 |
35 | /**
36 | * Created by almaz on 16.04.17.
37 | */
38 |
39 | public class MainFragment extends Fragment {
40 |
41 | private View rootView;
42 | private Spinner spinner1;
43 | private Spinner spinner2;
44 | private EditText textToTranslate;
45 | private ImageButton addToFavourites;
46 | private ImageButton changeLanguages;
47 | private TextView translatedText;
48 | private boolean isFavourite; // if current word is favourite.
49 | private boolean noTranslate; // do not translate at 1-st text changing. Need when initialize
50 | // with some text.
51 | private TextView apiInfo;
52 | private TextView link;
53 |
54 | /**
55 | * Initialize widget elements and create view
56 | * @param inflater
57 | * @param container
58 | * @param savedInstanceState
59 | * @return created view of fragment
60 | */
61 | @Nullable
62 | @Override
63 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
64 | @Nullable Bundle savedInstanceState) {
65 | rootView = inflater.inflate(R.layout.main_fragment, container, false);
66 | spinner1 = (Spinner) rootView.findViewById(R.id.languages1);
67 | spinner2 = (Spinner) rootView.findViewById(R.id.languages2);
68 | textToTranslate = (EditText) rootView.findViewById(R.id.textToTranslate);
69 | textToTranslate.setMovementMethod(new ScrollingMovementMethod());
70 | textToTranslate.setVerticalScrollBarEnabled(true);
71 | changeLanguages = (ImageButton) rootView.findViewById(R.id.changeLanguages);
72 | addToFavourites = (ImageButton) rootView.findViewById(R.id.addToFavourites1);
73 | translatedText = (TextView) rootView.findViewById(R.id.translatedText);
74 | translatedText.setMovementMethod(new ScrollingMovementMethod());
75 | translatedText.setVerticalScrollBarEnabled(true);
76 | link = (TextView) rootView.findViewById(R.id.link);
77 | apiInfo = (TextView) rootView.findViewById(R.id.api_info);
78 | setArgs();
79 | return rootView;
80 | }
81 |
82 | /**
83 | * Add listeners and set data.
84 | * @param view
85 | * @param savedInstanceState
86 | */
87 | @Override
88 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
89 | setSpinners();
90 | textChangedListener();
91 | addButtonListener();
92 | super.onViewCreated(view, savedInstanceState);
93 | }
94 |
95 | @Override
96 | public void onDestroyView() {
97 | SharedPreferences sharedPref = getActivity().getSharedPreferences("default", Context.MODE_PRIVATE);
98 | SharedPreferences.Editor editor = sharedPref.edit();
99 | editor.putInt("selection1", spinner1.getSelectedItemPosition());
100 | editor.putInt("selection2", spinner2.getSelectedItemPosition());
101 | editor.putString("textToTranslate", textToTranslate.getText().toString());
102 | editor.putString("translatedText", translatedText.getText().toString());
103 | editor.putBoolean("isFavourite", isFavourite);
104 | editor.apply();
105 | super.onDestroyView();
106 | }
107 |
108 | public void addToHistory() {
109 | String text = String.valueOf(textToTranslate.getText()).trim();
110 | if(!text.equals("")){
111 | DataBaseHelper dataBaseHelper = new DataBaseHelper(rootView.getContext(), "History.db");
112 | dataBaseHelper.insertWord(new Word(textToTranslate.getText().toString().trim(),
113 | translatedText.getText().toString(), spinner1.getSelectedItemPosition(),
114 | spinner2.getSelectedItemPosition()));
115 | dataBaseHelper.close();
116 | }
117 | }
118 |
119 | public void checkIfInFavourites(){
120 | String text = String.valueOf(textToTranslate.getText());
121 | if(!text.equals("")){
122 | addToFavourites.setVisibility(View.VISIBLE);
123 | apiInfo.setVisibility(View.VISIBLE);
124 | link.setVisibility(View.VISIBLE);
125 |
126 | DataBaseHelper dataBaseHelper = new DataBaseHelper(rootView.getContext(), "Favourites.db");
127 | if(dataBaseHelper.isInDataBase(new Word(text, translatedText.getText().toString(),
128 | spinner1.getSelectedItemPosition(), spinner2.getSelectedItemPosition()))) {
129 | addToFavourites.setImageResource(R.drawable.selected_favourites_icon);
130 | isFavourite = true;
131 | } else{
132 | addToFavourites.setImageResource(R.drawable.default_favourites_icon);
133 | isFavourite = false;
134 | }
135 | dataBaseHelper.close();
136 | } else{
137 | isFavourite = false;
138 | addToFavourites.setVisibility(View.INVISIBLE);
139 | apiInfo.setVisibility(View.INVISIBLE);
140 | link.setVisibility(View.INVISIBLE);
141 | translatedText.setText("");
142 | }
143 | }
144 |
145 | public void setArgs() {
146 | SharedPreferences sharedPref = getActivity().getSharedPreferences("default", Context.MODE_PRIVATE);
147 | String text = sharedPref.getString("textToTranslate", "");
148 | String translation = sharedPref.getString("translatedText", "");
149 | int selection1 = sharedPref.getInt("selection1", 0);
150 | int selection2 = sharedPref.getInt("selection2", 1);
151 | isFavourite = sharedPref.getBoolean("isFavourite", false);
152 | if (!text.equals("")) {
153 | noTranslate = true;
154 | textToTranslate.setText(text);
155 | spinner1.setSelection(selection1);
156 | spinner2.setSelection(selection2);
157 | translatedText.setText(translation);
158 | addToFavourites.setVisibility(View.VISIBLE);
159 | apiInfo.setVisibility(View.VISIBLE);
160 | link.setVisibility(View.VISIBLE);
161 | if(isFavourite){
162 | addToFavourites.setImageResource(R.drawable.selected_favourites_icon);
163 | } else{
164 | addToFavourites.setImageResource(R.drawable.default_favourites_icon);
165 | }
166 | }
167 | }
168 |
169 | public void addButtonListener() {
170 |
171 | addToFavourites.setOnClickListener(new View.OnClickListener() {
172 | @Override
173 | public void onClick(View v) {
174 | DataBaseHelper dataBaseHelper = new DataBaseHelper(v.getContext(),
175 | "Favourites.db");
176 | String text = textToTranslate.getText().toString().trim();
177 | String translation = translatedText.getText().toString();
178 | int source = spinner1.getSelectedItemPosition();
179 | int target = spinner2.getSelectedItemPosition();
180 | Word item = new Word(text, translation, source, target);
181 | if(dataBaseHelper.isInDataBase(item)){
182 | dataBaseHelper.deleteWord(item);
183 | addToFavourites.setImageResource(R.drawable.default_favourites_icon);
184 | isFavourite = false;
185 | } else{
186 | isFavourite = true;
187 | dataBaseHelper.insertWord(item);
188 | addToFavourites.setImageResource(R.drawable.selected_favourites_icon);
189 | }
190 | dataBaseHelper.close();
191 | }
192 | });
193 |
194 | changeLanguages.setOnClickListener(new View.OnClickListener() {
195 | @Override
196 | public void onClick(View v) {
197 | int sourceLng = spinner1.getSelectedItemPosition();
198 | int targetLng = spinner2.getSelectedItemPosition();
199 |
200 | spinner1.setSelection(targetLng);
201 | spinner2.setSelection(sourceLng);
202 |
203 | translate(textToTranslate.getText().toString().trim());
204 | }
205 | });
206 |
207 | }
208 |
209 | public void setSpinners() {
210 | // Spinner Drop down elements
211 | List categories = new ArrayList();
212 |
213 | if(Locale.getDefault().getLanguage().equals("en")) {
214 | Collections.addAll(categories, Languages.getLangsEN());
215 | } else{
216 | Collections.addAll(categories, Languages.getLangsRU());
217 | }
218 |
219 | // Creating adapter for spinner
220 | ArrayAdapter dataAdapter = new ArrayAdapter(getContext(),
221 | android.R.layout.simple_spinner_item, categories);
222 |
223 | // Drop down layout style - list view with radio button
224 | dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
225 |
226 | // attaching data adapter to spinner
227 | spinner1.setAdapter(dataAdapter);
228 | spinner2.setAdapter(dataAdapter);
229 | spinner2.setSelection(1);
230 | }
231 |
232 | public void textChangedListener() {
233 |
234 | // Translate the text after 500 milliseconds when user ends to typing
235 | RxTextView.textChanges(textToTranslate).
236 | filter(charSequence -> charSequence.length() > 0).
237 | debounce(500, TimeUnit.MILLISECONDS).
238 | subscribe(new Action1() {
239 | @Override
240 | public void call(CharSequence charSequence) {
241 | translate(charSequence.toString().trim());
242 | }
243 | });
244 |
245 | RxTextView.textChanges(textToTranslate).
246 | filter(charSequence -> charSequence.length() == 0).
247 | subscribe(new Action1() {
248 | @Override
249 | public void call(CharSequence charSequence) {
250 | getActivity().runOnUiThread(new Runnable() {
251 | @Override
252 | public void run() {
253 | checkIfInFavourites();
254 | }
255 | });
256 | }
257 | });
258 | }
259 |
260 | private void translate(String text){
261 | if(noTranslate){
262 | noTranslate = false;
263 | return;
264 | }
265 |
266 | String APIKey = "";
267 | String language1 = String.valueOf(spinner1.getSelectedItem());
268 | String language2 = String.valueOf(spinner2.getSelectedItem());
269 |
270 | Retrofit query = new Retrofit.Builder().baseUrl("https://translate.yandex.net/").
271 | addConverterFactory(GsonConverterFactory.create()).build();
272 | APIHelper apiHelper = query.create(APIHelper.class);
273 | Call call = apiHelper.getTranslation(APIKey, text,
274 | langCode(language1) + "-" + langCode(language2));
275 |
276 | call.enqueue(new Callback() {
277 | @Override
278 | public void onResponse(Call call, Response response) {
279 | if(response.isSuccessful()){
280 | getActivity().runOnUiThread(new Runnable() {
281 | @Override
282 | public void run() {
283 | translatedText.setText(response.body().getText().get(0));
284 | checkIfInFavourites();
285 | addToHistory();
286 | }
287 | });
288 | }
289 | }
290 |
291 | @Override
292 | public void onFailure(Call call, Throwable t) {}
293 | });
294 | }
295 |
296 | public String langCode(String selectedLang) {
297 | String code = null;
298 |
299 | if(Locale.getDefault().getLanguage().equals("en")) {
300 | for (int i = 0; i < Languages.getLangsEN().length; i++) {
301 | if(selectedLang.equals(Languages.getLangsEN()[i])){
302 | code = Languages.getLangCodeEN(i);
303 | }
304 | }
305 | } else{
306 | for (int i = 0; i < Languages.getLangsRU().length; i++) {
307 | if(selectedLang.equals(Languages.getLangsRU()[i])){
308 | code = Languages.getLangCodeRU(i);
309 | }
310 | }
311 | }
312 | return code;
313 | }
314 | }
315 |
--------------------------------------------------------------------------------