mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 12:02:16 +02:00
Remove code related to translation from project
This commit is contained in:
parent
8d9e79f90b
commit
6dff1b63c5
@ -342,13 +342,6 @@
|
||||
android:configChanges="keyboardHidden|orientation|locale|screenSize"
|
||||
>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.ichi2.anki.multimediacard.activity.TranslationActivity"
|
||||
android:label="@string/title_activity_translation"
|
||||
android:exported="false"
|
||||
android:configChanges="keyboardHidden|orientation|locale|screenSize"
|
||||
>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.ichi2.anki.multimediacard.activity.LoadPronunciationActivity"
|
||||
android:label="@string/multimedia_editor_text_field_editing_say"
|
||||
|
@ -1,382 +0,0 @@
|
||||
/****************************************************************************************
|
||||
* Copyright (c) 2013 Bibek Shrestha <bibekshrestha@gmail.com> *
|
||||
* Copyright (c) 2013 Zaur Molotnikov <qutorial@gmail.com> *
|
||||
* Copyright (c) 2013 Nicolas Raoul <nicolas.raoul@gmail.com> *
|
||||
* Copyright (c) 2013 Flavio Lerda <flerda@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify it under *
|
||||
* the terms of the GNU General Public License as published by the Free Software *
|
||||
* Foundation; either version 3 of the License, or (at your option) any later *
|
||||
* version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
package com.ichi2.anki.multimediacard.activity
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import com.fasterxml.jackson.core.JsonProcessingException
|
||||
import com.ichi2.anki.AnkiDroidApp
|
||||
import com.ichi2.anki.AnkiSerialization
|
||||
import com.ichi2.anki.R
|
||||
import com.ichi2.anki.UIUtils.showThemedToast
|
||||
import com.ichi2.anki.multimediacard.glosbe.json.Response
|
||||
import com.ichi2.anki.multimediacard.language.LanguagesListerGlosbe
|
||||
import com.ichi2.anki.multimediacard.language.LanguagesListerGlosbe.Companion.requestToResponseLangCode
|
||||
import com.ichi2.anki.runtimetools.TaskOperations.stopTaskGracefully
|
||||
import com.ichi2.anki.web.HttpFetcher.fetchThroughHttp
|
||||
import com.ichi2.async.Connection
|
||||
import com.ichi2.libanki.Utils
|
||||
import com.ichi2.themes.Themes.disableXiaomiForceDarkMode
|
||||
import com.ichi2.ui.FixedTextView
|
||||
import com.ichi2.utils.AdaptionUtil
|
||||
import com.ichi2.utils.KotlinCleanup
|
||||
import timber.log.Timber
|
||||
import java.io.UnsupportedEncodingException
|
||||
import java.net.URLEncoder
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Activity used now with Glosbe.com to enable translation of words.
|
||||
* FIXME why isn't this extending from our base classes?
|
||||
*/
|
||||
|
||||
open class TranslationActivity : FragmentActivity(), DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
|
||||
private lateinit var mSource: String
|
||||
private lateinit var mTranslation: String
|
||||
private lateinit var mLanguageLister: LanguagesListerGlosbe
|
||||
private lateinit var mSpinnerFrom: Spinner
|
||||
private lateinit var mSpinnerTo: Spinner
|
||||
private lateinit var mLoadingLayout: View
|
||||
private lateinit var mLoadingLayoutTitle: TextView
|
||||
private lateinit var mLoadingLayoutMessage: TextView
|
||||
private lateinit var mMainLayout: LinearLayout
|
||||
private lateinit var mWebServiceAddress: String
|
||||
private lateinit var mPossibleTranslations: ArrayList<String>
|
||||
private lateinit var mLangCodeTo: String
|
||||
private lateinit var mTranslationLoadPost: BackgroundPost
|
||||
private fun finishCancel() {
|
||||
val resultData = Intent()
|
||||
setResult(RESULT_CANCELED, resultData)
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
disableXiaomiForceDarkMode(this)
|
||||
if (AdaptionUtil.isUserATestClient) {
|
||||
finishCancel()
|
||||
return
|
||||
}
|
||||
if (savedInstanceState != null) {
|
||||
val b = savedInstanceState.getBoolean(BUNDLE_KEY_SHUT_OFF, false)
|
||||
if (b) {
|
||||
finishCancel()
|
||||
return
|
||||
}
|
||||
}
|
||||
setContentView(R.layout.activity_translation)
|
||||
mLoadingLayout = findViewById(R.id.progress_bar_layout)
|
||||
mLoadingLayoutTitle = findViewById(R.id.progress_bar_layout_title)
|
||||
mLoadingLayoutMessage = findViewById(R.id.progress_bar_layout_message)
|
||||
mSource = try {
|
||||
intent.extras!!.getString(EXTRA_SOURCE)!!
|
||||
} catch (e: Exception) {
|
||||
Timber.w(e)
|
||||
""
|
||||
}
|
||||
|
||||
// If translation fails this is a default - source will be returned.
|
||||
mTranslation = mSource
|
||||
mMainLayout = findViewById(R.id.MainLayoutInTranslationActivity)
|
||||
val tv: TextView = FixedTextView(this)
|
||||
tv.text = getText(R.string.multimedia_editor_trans_poweredglosbe)
|
||||
mMainLayout.addView(tv)
|
||||
val tvFrom: TextView = FixedTextView(this)
|
||||
tvFrom.text = getText(R.string.multimedia_editor_trans_from)
|
||||
mMainLayout.addView(tvFrom)
|
||||
mLanguageLister = LanguagesListerGlosbe()
|
||||
mSpinnerFrom = Spinner(this)
|
||||
val adapter = ArrayAdapter(
|
||||
this, android.R.layout.simple_spinner_item,
|
||||
mLanguageLister.languages
|
||||
)
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
mSpinnerFrom.adapter = adapter
|
||||
mMainLayout.addView(mSpinnerFrom)
|
||||
val tvTo: TextView = FixedTextView(this)
|
||||
tvTo.text = getText(R.string.multimedia_editor_trans_to)
|
||||
mMainLayout.addView(tvTo)
|
||||
mSpinnerTo = Spinner(this)
|
||||
val adapterTo = ArrayAdapter(
|
||||
this, android.R.layout.simple_spinner_item,
|
||||
mLanguageLister.languages
|
||||
)
|
||||
adapterTo.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
mSpinnerTo.adapter = adapterTo
|
||||
mMainLayout.addView(mSpinnerTo)
|
||||
val preferences = AnkiDroidApp.getSharedPrefs(baseContext)
|
||||
|
||||
// Try to set spinner value to last selected position
|
||||
val fromLang = preferences.getString("translatorLastLanguageFrom", "")
|
||||
val toLang = preferences.getString("translatorLastLanguageTo", "")
|
||||
mSpinnerFrom.setSelection(getSpinnerIndex(mSpinnerFrom, fromLang))
|
||||
mSpinnerTo.setSelection(getSpinnerIndex(mSpinnerTo, toLang))
|
||||
// Setup button
|
||||
val btnDone = Button(this)
|
||||
btnDone.text = getText(R.string.multimedia_editor_trans_translate)
|
||||
btnDone.setOnClickListener {
|
||||
// Remember currently selected language
|
||||
val fromLang1 = mSpinnerFrom.selectedItem.toString()
|
||||
val toLang1 = mSpinnerTo.selectedItem.toString()
|
||||
preferences.edit().putString("translatorLastLanguageFrom", fromLang1).apply()
|
||||
preferences.edit().putString("translatorLastLanguageTo", toLang1).apply()
|
||||
// Get translation
|
||||
translate()
|
||||
}
|
||||
mMainLayout.addView(btnDone)
|
||||
}
|
||||
|
||||
private fun showProgressBar(title: CharSequence, message: CharSequence) {
|
||||
mMainLayout.visibility = View.GONE
|
||||
mLoadingLayout.visibility = View.VISIBLE
|
||||
mLoadingLayoutTitle.text = title
|
||||
mLoadingLayoutMessage.text = message
|
||||
}
|
||||
|
||||
private fun hideProgressBar() {
|
||||
mLoadingLayout.visibility = View.GONE
|
||||
mMainLayout.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
menuInflater.inflate(R.menu.activity_translation, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
@Suppress("deprecation") // #7108: AsyncTask
|
||||
private inner class BackgroundPost : android.os.AsyncTask<Void?, Void?, String>() {
|
||||
override fun doInBackground(vararg params: Void?): String {
|
||||
return fetchThroughHttp(mWebServiceAddress)
|
||||
}
|
||||
|
||||
override fun onPostExecute(result: String) {
|
||||
hideProgressBar()
|
||||
mTranslation = result
|
||||
showPickTranslationDialog()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("deprecation") // #7108: AsyncTask
|
||||
protected fun translate() {
|
||||
if (!Connection.isOnline()) {
|
||||
showToast(gtxt(R.string.network_no_connection))
|
||||
return
|
||||
}
|
||||
showProgressBar(
|
||||
getText(R.string.multimedia_editor_progress_wait_title),
|
||||
getText(R.string.multimedia_editor_trans_translating_online)
|
||||
)
|
||||
mWebServiceAddress = computeAddress()
|
||||
try {
|
||||
mTranslationLoadPost = BackgroundPost()
|
||||
mTranslationLoadPost.execute()
|
||||
} catch (e: Exception) {
|
||||
Timber.w(e)
|
||||
hideProgressBar()
|
||||
showToast(getText(R.string.multimedia_editor_something_wrong))
|
||||
}
|
||||
}
|
||||
|
||||
private fun computeAddress(): String {
|
||||
var address = "https://glosbe.com/gapi/translate?from=FROMLANG&dest=TOLANG&format=json&phrase=SOURCE&pretty=true"
|
||||
val strFrom = mSpinnerFrom.selectedItem.toString()
|
||||
// Conversion to iso, lister created before.
|
||||
val langCodeFrom = mLanguageLister.getCodeFor(strFrom)
|
||||
val strTo = mSpinnerTo.selectedItem.toString()
|
||||
mLangCodeTo = mLanguageLister.getCodeFor(strTo)!!
|
||||
val query: String? = try {
|
||||
URLEncoder.encode(mSource, "utf-8")
|
||||
} catch (e: UnsupportedEncodingException) {
|
||||
Timber.w(e)
|
||||
mSource.replace(" ", "%20")
|
||||
}
|
||||
address = address.replace("FROMLANG".toRegex(), langCodeFrom!!).replace("TOLANG".toRegex(), mLangCodeTo)
|
||||
.replace("SOURCE".toRegex(), query!!)
|
||||
return address
|
||||
}
|
||||
|
||||
private fun gtxt(id: Int): String {
|
||||
return getText(id).toString()
|
||||
}
|
||||
|
||||
private fun showToastLong(text: CharSequence) {
|
||||
showThemedToast(this, text, false)
|
||||
}
|
||||
|
||||
private fun showPickTranslationDialog() {
|
||||
if (mTranslation.startsWith("FAILED")) {
|
||||
returnFailure(getText(R.string.multimedia_editor_trans_getting_failure).toString())
|
||||
return
|
||||
}
|
||||
val objectMapper = AnkiSerialization.objectMapper
|
||||
|
||||
val resp: Response? = try {
|
||||
objectMapper.readValue(mTranslation, Response::class.java)
|
||||
} catch (e: JsonProcessingException) {
|
||||
Timber.w(e)
|
||||
returnFailure(getText(R.string.multimedia_editor_trans_getting_failure).toString())
|
||||
return
|
||||
}
|
||||
|
||||
if (resp == null) {
|
||||
returnFailure(getText(R.string.multimedia_editor_trans_getting_failure).toString())
|
||||
return
|
||||
}
|
||||
|
||||
if (!resp.result!!.contentEquals("ok")) {
|
||||
if (!mSource.lowercase(Locale.getDefault()).contentEquals(mSource)) {
|
||||
showToastLong(gtxt(R.string.multimedia_editor_word_search_try_lower_case))
|
||||
}
|
||||
|
||||
returnFailure(getText(R.string.multimedia_editor_trans_getting_failure).toString())
|
||||
return
|
||||
}
|
||||
|
||||
mPossibleTranslations = parseJson(resp, mLangCodeTo)
|
||||
|
||||
if (mPossibleTranslations.isEmpty()) {
|
||||
if (!mSource.lowercase(Locale.getDefault()).contentEquals(mSource)) {
|
||||
showToastLong(gtxt(R.string.multimedia_editor_word_search_try_lower_case))
|
||||
}
|
||||
|
||||
returnFailure(getText(R.string.multimedia_editor_error_word_not_found).toString())
|
||||
return
|
||||
}
|
||||
|
||||
val fragment = PickStringDialogFragment()
|
||||
|
||||
fragment.setChoices(mPossibleTranslations)
|
||||
fragment.setOnclickListener(this)
|
||||
fragment.setTitle(getText(R.string.multimedia_editor_trans_pick_translation).toString())
|
||||
|
||||
fragment.show(this.supportFragmentManager, "pick.translation")
|
||||
}
|
||||
|
||||
private fun returnTheTranslation() {
|
||||
val resultData = Intent()
|
||||
resultData.putExtra(EXTRA_TRANSLATION, mTranslation)
|
||||
setResult(RESULT_OK, resultData)
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun returnFailure(explanation: String) {
|
||||
showToast(explanation)
|
||||
setResult(RESULT_CANCELED)
|
||||
hideProgressBar()
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun showToast(text: CharSequence) {
|
||||
showThemedToast(this, text, true)
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putBoolean(BUNDLE_KEY_SHUT_OFF, true)
|
||||
}
|
||||
|
||||
override fun onClick(dialog: DialogInterface, which: Int) {
|
||||
mTranslation = mPossibleTranslations[which]
|
||||
returnTheTranslation()
|
||||
}
|
||||
|
||||
override fun onCancel(dialog: DialogInterface) {
|
||||
stopWorking()
|
||||
}
|
||||
|
||||
private fun stopWorking() {
|
||||
stopTaskGracefully(mTranslationLoadPost)
|
||||
hideProgressBar()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
stopWorking()
|
||||
}
|
||||
|
||||
private fun getSpinnerIndex(spinner: Spinner, myString: String?): Int {
|
||||
var index = 0
|
||||
for (i in 0 until spinner.count) {
|
||||
if (spinner.getItemAtPosition(i) == myString) {
|
||||
index = i
|
||||
}
|
||||
}
|
||||
return index
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val BUNDLE_KEY_SHUT_OFF = "key.multimedia.shut.off"
|
||||
|
||||
// Something to translate
|
||||
const val EXTRA_SOURCE = "translation.activity.extra.source"
|
||||
|
||||
// Translated result
|
||||
const val EXTRA_TRANSLATION = "translation.activity.extra.translation"
|
||||
private fun parseJson(resp: Response, languageCodeTo: String?): ArrayList<String> {
|
||||
|
||||
/*
|
||||
* The algorithm below includes the parsing of glosbe results. Glosbe.com returns a list of different phrases in
|
||||
* source and destination languages. This is done, probably, to improve the reader's understanding. We leave
|
||||
* here only the translations to the destination language.
|
||||
*/
|
||||
KotlinCleanup("mapNotNull")
|
||||
val tucs = resp.tuc ?: return ArrayList(0)
|
||||
val res = ArrayList<String>(tucs.size)
|
||||
val desiredLang = requestToResponseLangCode(languageCodeTo!!)
|
||||
for (tuc in tucs) {
|
||||
if (tuc == null) {
|
||||
continue
|
||||
}
|
||||
val meanings = tuc.meanings
|
||||
if (meanings != null) {
|
||||
for (meaning in meanings) {
|
||||
if (meaning == null) {
|
||||
continue
|
||||
}
|
||||
if (meaning.language == null) {
|
||||
continue
|
||||
}
|
||||
if (meaning.language!!.contentEquals(desiredLang)) {
|
||||
val unescapedString = Utils.unescape(meaning.text)
|
||||
res.add(unescapedString)
|
||||
}
|
||||
}
|
||||
}
|
||||
val phrase = tuc.phrase
|
||||
if (phrase != null) {
|
||||
if (phrase.language == null) {
|
||||
continue
|
||||
}
|
||||
if (phrase.language!!.contentEquals(desiredLang)) {
|
||||
val unescapedString = Utils.unescape(phrase.text)
|
||||
res.add(unescapedString)
|
||||
}
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
}
|
||||
}
|
@ -23,20 +23,14 @@ import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.view.Gravity
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import com.ichi2.anki.R
|
||||
import com.ichi2.anki.UIUtils.showThemedToast
|
||||
import com.ichi2.anki.multimediacard.activity.LoadPronunciationActivity
|
||||
import com.ichi2.anki.multimediacard.activity.PickStringDialogFragment
|
||||
import com.ichi2.anki.multimediacard.activity.TranslationActivity
|
||||
import com.ichi2.compat.CompatHelper
|
||||
import com.ichi2.ui.FixedEditText
|
||||
import com.ichi2.ui.FixedTextView
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
|
||||
@ -61,16 +55,11 @@ class BasicTextFieldController : FieldControllerBase(), IFieldController, Dialog
|
||||
val p = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1F)
|
||||
createCloneButton(layoutTools, p)
|
||||
createClearButton(layoutTools, p)
|
||||
// search label
|
||||
val searchLabel: TextView = FixedTextView(mActivity)
|
||||
searchLabel.setText(R.string.multimedia_editor_text_field_editing_search_label)
|
||||
layout.addView(searchLabel)
|
||||
// search buttons
|
||||
val layoutTools2 = LinearLayout(mActivity)
|
||||
layoutTools2.orientation = LinearLayout.HORIZONTAL
|
||||
layout.addView(layoutTools2)
|
||||
createTranslateButton(layoutTools2, p)
|
||||
createPronounceButton(layoutTools2, p)
|
||||
createPronounceButton(layoutTools2, LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT))
|
||||
}
|
||||
|
||||
private fun gtxt(id: Int): String {
|
||||
@ -104,47 +93,6 @@ class BasicTextFieldController : FieldControllerBase(), IFieldController, Dialog
|
||||
layoutTools.addView(btnPronounce, p)
|
||||
}
|
||||
|
||||
// Here is all the functionality to provide translations
|
||||
private fun createTranslateButton(layoutTool: LinearLayout, ps: LinearLayout.LayoutParams) {
|
||||
val btnTranslate = Button(mActivity)
|
||||
btnTranslate.text = gtxt(R.string.multimedia_editor_text_field_editing_translate)
|
||||
btnTranslate.setOnClickListener {
|
||||
val source = mEditText.text.toString()
|
||||
|
||||
// Checks and warnings
|
||||
if (source.isEmpty()) {
|
||||
showToast(gtxt(R.string.multimedia_editor_text_field_editing_no_text))
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (source.contains(" ")) {
|
||||
showToast(gtxt(R.string.multimedia_editor_text_field_editing_many_words))
|
||||
}
|
||||
|
||||
// Pick from two translation sources
|
||||
val fragment = PickStringDialogFragment()
|
||||
val translationSources = ArrayList<String>(2)
|
||||
translationSources.add("Glosbe.com")
|
||||
// Chromebooks do not support dependent apps yet.
|
||||
if (!CompatHelper.isChromebook) {
|
||||
translationSources.add("ColorDict")
|
||||
}
|
||||
fragment.setChoices(translationSources)
|
||||
fragment.setOnclickListener { _: DialogInterface?, which: Int ->
|
||||
val translationSource = translationSources[which]
|
||||
if ("Glosbe.com" == translationSource) {
|
||||
startTranslationWithGlosbe()
|
||||
} else if ("ColorDict" == translationSource) {
|
||||
startTranslationWithColorDict()
|
||||
}
|
||||
}
|
||||
fragment.setTitle(gtxt(R.string.multimedia_editor_trans_pick_translation_source))
|
||||
fragment.show(mActivity.supportFragmentManager, "pick.translation.source")
|
||||
}
|
||||
layoutTool.addView(btnTranslate, ps)
|
||||
|
||||
// flow continues in Start Translation with...
|
||||
}
|
||||
|
||||
/**
|
||||
* @param layoutTools This creates a button, which will call a dialog, allowing to pick from another note's fields
|
||||
* one, and use it's value in the current one.
|
||||
@ -197,16 +145,7 @@ class BasicTextFieldController : FieldControllerBase(), IFieldController, Dialog
|
||||
* activity are received.
|
||||
*/
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (requestCode == REQUEST_CODE_TRANSLATE_GLOSBE && resultCode == Activity.RESULT_OK) {
|
||||
// Translation returned.
|
||||
try {
|
||||
val translation = data!!.extras!![TranslationActivity.EXTRA_TRANSLATION].toString()
|
||||
mEditText.setText(translation)
|
||||
} catch (e: Exception) {
|
||||
Timber.w(e)
|
||||
showToast(gtxt(R.string.multimedia_editor_something_wrong))
|
||||
}
|
||||
} else if (requestCode == REQUEST_CODE_PRONUNCIATION && resultCode == Activity.RESULT_OK) {
|
||||
if (requestCode == REQUEST_CODE_PRONUNCIATION && resultCode == Activity.RESULT_OK) {
|
||||
try {
|
||||
val pronouncePath = data!!.extras!![LoadPronunciationActivity.EXTRA_PRONUNCIATION_FILE_PATH]
|
||||
.toString()
|
||||
@ -223,10 +162,6 @@ class BasicTextFieldController : FieldControllerBase(), IFieldController, Dialog
|
||||
Timber.w(e)
|
||||
showToast(gtxt(R.string.multimedia_editor_pron_pronunciation_failed))
|
||||
}
|
||||
} else if (requestCode == REQUEST_CODE_TRANSLATE_COLORDICT && resultCode == Activity.RESULT_OK) {
|
||||
// String subject = data.getStringExtra(Intent.EXTRA_SUBJECT);
|
||||
val text = data!!.getStringExtra(Intent.EXTRA_TEXT)
|
||||
mEditText.setText(text)
|
||||
}
|
||||
}
|
||||
|
||||
@ -251,62 +186,12 @@ class BasicTextFieldController : FieldControllerBase(), IFieldController, Dialog
|
||||
showThemedToast(mActivity, text, true)
|
||||
}
|
||||
|
||||
// Only now not all APIs are used, may be later, they will be.
|
||||
@Suppress("Unused_Variable")
|
||||
private fun startTranslationWithColorDict() {
|
||||
val PICK_RESULT_ACTION = "colordict.intent.action.PICK_RESULT"
|
||||
val SEARCH_ACTION = "colordict.intent.action.SEARCH"
|
||||
val EXTRA_QUERY = "EXTRA_QUERY"
|
||||
val EXTRA_FULLSCREEN = "EXTRA_FULLSCREEN"
|
||||
val EXTRA_HEIGHT = "EXTRA_HEIGHT"
|
||||
val EXTRA_WIDTH = "EXTRA_WIDTH"
|
||||
val EXTRA_GRAVITY = "EXTRA_GRAVITY"
|
||||
val EXTRA_MARGIN_LEFT = "EXTRA_MARGIN_LEFT"
|
||||
val EXTRA_MARGIN_TOP = "EXTRA_MARGIN_TOP"
|
||||
val EXTRA_MARGIN_BOTTOM = "EXTRA_MARGIN_BOTTOM"
|
||||
val EXTRA_MARGIN_RIGHT = "EXTRA_MARGIN_RIGHT"
|
||||
val intent = Intent(PICK_RESULT_ACTION)
|
||||
intent.putExtra(EXTRA_QUERY, mEditText.text.toString()) // Search
|
||||
// Query
|
||||
intent.putExtra(EXTRA_FULLSCREEN, false) //
|
||||
// intent.putExtra(EXTRA_HEIGHT, 400); //400pixel, if you don't specify,
|
||||
// fill_parent"
|
||||
intent.putExtra(EXTRA_GRAVITY, Gravity.BOTTOM)
|
||||
// intent.putExtra(EXTRA_MARGIN_LEFT, 100);
|
||||
if (!isIntentAvailable(mActivity, intent)) {
|
||||
showToast(gtxt(R.string.multimedia_editor_trans_install_color_dict))
|
||||
return
|
||||
}
|
||||
mActivity.startActivityForResultWithoutAnimation(intent, REQUEST_CODE_TRANSLATE_COLORDICT)
|
||||
}
|
||||
|
||||
private fun startTranslationWithGlosbe() {
|
||||
val source = mEditText.text.toString()
|
||||
val intent = Intent(mActivity, TranslationActivity::class.java)
|
||||
intent.putExtra(TranslationActivity.EXTRA_SOURCE, source)
|
||||
mActivity.startActivityForResultWithoutAnimation(intent, REQUEST_CODE_TRANSLATE_GLOSBE)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
companion object {
|
||||
// Additional activities are started to perform translation/pronunciation search and
|
||||
// so on, here are their request codes, to differentiate, when they return.
|
||||
private const val REQUEST_CODE_TRANSLATE_GLOSBE = 101
|
||||
// code to identify the request to fetch pronunciations
|
||||
private const val REQUEST_CODE_PRONUNCIATION = 102
|
||||
private const val REQUEST_CODE_TRANSLATE_COLORDICT = 103
|
||||
|
||||
/**
|
||||
* @param context context with the PackageManager
|
||||
* @param intent intent for state data
|
||||
* @return Needed to check, if the Color Dict is installed
|
||||
*/
|
||||
private fun isIntentAvailable(context: Context, intent: Intent): Boolean {
|
||||
val packageManager = context.packageManager
|
||||
val list: List<*> = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
|
||||
return list.isNotEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,48 +0,0 @@
|
||||
/****************************************************************************************
|
||||
* Copyright (c) 2013 Bibek Shrestha <bibekshrestha@gmail.com> *
|
||||
* Copyright (c) 2013 Zaur Molotnikov <qutorial@gmail.com> *
|
||||
* Copyright (c) 2013 Nicolas Raoul <nicolas.raoul@gmail.com> *
|
||||
* Copyright (c) 2013 Flavio Lerda <flerda@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify it under *
|
||||
* the terms of the GNU General Public License as published by the Free Software *
|
||||
* Foundation; either version 3 of the License, or (at your option) any later *
|
||||
* version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
package com.ichi2.anki.multimediacard.glosbe.json;
|
||||
|
||||
/**
|
||||
* This is one of the classes, automatically generated to transform json replies from glosbe.com
|
||||
*/
|
||||
public class Meaning {
|
||||
private String mLanguage;
|
||||
private String mText;
|
||||
|
||||
|
||||
public String getLanguage() {
|
||||
return this.mLanguage;
|
||||
}
|
||||
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.mLanguage = language;
|
||||
}
|
||||
|
||||
|
||||
public String getText() {
|
||||
return this.mText;
|
||||
}
|
||||
|
||||
|
||||
public void setText(String text) {
|
||||
this.mText = text;
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/****************************************************************************************
|
||||
* Copyright (c) 2013 Bibek Shrestha <bibekshrestha@gmail.com> *
|
||||
* Copyright (c) 2013 Zaur Molotnikov <qutorial@gmail.com> *
|
||||
* Copyright (c) 2013 Nicolas Raoul <nicolas.raoul@gmail.com> *
|
||||
* Copyright (c) 2013 Flavio Lerda <flerda@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify it under *
|
||||
* the terms of the GNU General Public License as published by the Free Software *
|
||||
* Foundation; either version 3 of the License, or (at your option) any later *
|
||||
* version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
package com.ichi2.anki.multimediacard.glosbe.json;
|
||||
|
||||
/**
|
||||
* This is one of the classes, automatically generated to transform json replies from glosbe.com
|
||||
*/
|
||||
public class Phrase {
|
||||
private String mLanguage;
|
||||
private String mText;
|
||||
|
||||
|
||||
public String getLanguage() {
|
||||
return this.mLanguage;
|
||||
}
|
||||
|
||||
|
||||
public void setLanguage(String l) {
|
||||
this.mLanguage = l;
|
||||
}
|
||||
|
||||
|
||||
public String getText() {
|
||||
return this.mText;
|
||||
}
|
||||
|
||||
|
||||
public void setText(String text) {
|
||||
this.mText = text;
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
/****************************************************************************************
|
||||
* Copyright (c) 2013 Bibek Shrestha <bibekshrestha@gmail.com> *
|
||||
* Copyright (c) 2013 Zaur Molotnikov <qutorial@gmail.com> *
|
||||
* Copyright (c) 2013 Nicolas Raoul <nicolas.raoul@gmail.com> *
|
||||
* Copyright (c) 2013 Flavio Lerda <flerda@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify it under *
|
||||
* the terms of the GNU General Public License as published by the Free Software *
|
||||
* Foundation; either version 3 of the License, or (at your option) any later *
|
||||
* version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
package com.ichi2.anki.multimediacard.glosbe.json;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zaur This is one of the classes, automatically generated to transform json replies from glosbe.com This is
|
||||
* the root class, from which response starts.
|
||||
*/
|
||||
public class Response {
|
||||
private String mDest;
|
||||
private String mFrom;
|
||||
private String mPhrase;
|
||||
private String mResult;
|
||||
private List<Tuc> mTuc;
|
||||
|
||||
|
||||
public String getDest() {
|
||||
return this.mDest;
|
||||
}
|
||||
|
||||
|
||||
public void setDest(String dest) {
|
||||
this.mDest = dest;
|
||||
}
|
||||
|
||||
|
||||
public String getFrom() {
|
||||
return this.mFrom;
|
||||
}
|
||||
|
||||
|
||||
public void setFrom(String from) {
|
||||
this.mFrom = from;
|
||||
}
|
||||
|
||||
|
||||
public String getPhrase() {
|
||||
return this.mPhrase;
|
||||
}
|
||||
|
||||
|
||||
public void setPhrase(String phrase) {
|
||||
this.mPhrase = phrase;
|
||||
}
|
||||
|
||||
|
||||
public String getResult() {
|
||||
return this.mResult;
|
||||
}
|
||||
|
||||
|
||||
public void setResult(String result) {
|
||||
this.mResult = result;
|
||||
}
|
||||
|
||||
|
||||
public List<Tuc> getTuc() {
|
||||
return this.mTuc;
|
||||
}
|
||||
|
||||
|
||||
public void setTuc(List<Tuc> tuc) {
|
||||
this.mTuc = tuc;
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
/****************************************************************************************
|
||||
* Copyright (c) 2013 Bibek Shrestha <bibekshrestha@gmail.com> *
|
||||
* Copyright (c) 2013 Zaur Molotnikov <qutorial@gmail.com> *
|
||||
* Copyright (c) 2013 Nicolas Raoul <nicolas.raoul@gmail.com> *
|
||||
* Copyright (c) 2013 Flavio Lerda <flerda@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify it under *
|
||||
* the terms of the GNU General Public License as published by the Free Software *
|
||||
* Foundation; either version 3 of the License, or (at your option) any later *
|
||||
* version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
package com.ichi2.anki.multimediacard.glosbe.json;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is one of the classes, automatically generated to transform json replies from glosbe.com
|
||||
*/
|
||||
public class Tuc {
|
||||
private List<Number> mAuthors;
|
||||
private Number mMeaningId;
|
||||
private List<Meaning> mMeanings;
|
||||
private Phrase mPhrase;
|
||||
|
||||
|
||||
public List<Number> getAuthors() {
|
||||
return this.mAuthors;
|
||||
}
|
||||
|
||||
|
||||
public void setAuthors(List<Number> authors) {
|
||||
this.mAuthors = authors;
|
||||
}
|
||||
|
||||
|
||||
public Number getMeaningId() {
|
||||
return this.mMeaningId;
|
||||
}
|
||||
|
||||
|
||||
public void setMeaningId(Number meaningId) {
|
||||
this.mMeaningId = meaningId;
|
||||
}
|
||||
|
||||
|
||||
public List<Meaning> getMeanings() {
|
||||
return this.mMeanings;
|
||||
}
|
||||
|
||||
|
||||
public void setMeanings(List<Meaning> meanings) {
|
||||
this.mMeanings = meanings;
|
||||
}
|
||||
|
||||
|
||||
public Phrase getPhrase() {
|
||||
return this.mPhrase;
|
||||
}
|
||||
|
||||
|
||||
public void setPhrase(Phrase phrase) {
|
||||
this.mPhrase = phrase;
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
/****************************************************************************************
|
||||
* Copyright (c) 2013 Bibek Shrestha <bibekshrestha@gmail.com> *
|
||||
* Copyright (c) 2013 Zaur Molotnikov <qutorial@gmail.com> *
|
||||
* Copyright (c) 2013 Nicolas Raoul <nicolas.raoul@gmail.com> *
|
||||
* Copyright (c) 2013 Flavio Lerda <flerda@gmail.com> *
|
||||
* Copyright (c) 2014 Timothy Rae <perceptualchaos2@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify it under *
|
||||
* the terms of the GNU General Public License as published by the Free Software *
|
||||
* Foundation; either version 3 of the License, or (at your option) any later *
|
||||
* version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
package com.ichi2.anki.multimediacard.language
|
||||
|
||||
import com.ichi2.utils.HashUtil.HashMapInit
|
||||
import java.util.HashMap
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* This language lister is used to call glosbe.com translation services.
|
||||
* <p>
|
||||
* Glosbe expects the languages to follow the ISO 639-3 codes.
|
||||
* <p>
|
||||
* It can be extended freely here, to support more languages.
|
||||
*/
|
||||
class LanguagesListerGlosbe : LanguageListerBase() {
|
||||
companion object {
|
||||
private var locale_map: HashMap<String, Locale>? = null
|
||||
|
||||
/**
|
||||
* Convert from 3 letter ISO 639-2 language code to ISO 639-1
|
||||
* @param req 3 letter language code
|
||||
* @return 2 letter language code
|
||||
*/
|
||||
@JvmStatic
|
||||
fun requestToResponseLangCode(req: String): String {
|
||||
if (locale_map == null) {
|
||||
val languages = Locale.getISOLanguages()
|
||||
locale_map = HashMapInit(languages.size)
|
||||
for (language in languages) {
|
||||
val locale = Locale(language)
|
||||
locale_map!![locale.isO3Language] = locale
|
||||
}
|
||||
}
|
||||
return locale_map!![req]!!.language
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
val languages = arrayOf(
|
||||
"eng", "deu", "jpn", "fra", "spa", "pol", "ita", "rus",
|
||||
"ces", "zho", "nld", "por", "swe", "hrv", "hin", "hun", "vie", "ara", "tur"
|
||||
)
|
||||
// Java Locale uses ISO 639-2 rather than 639-3 so we currently only support the subset of
|
||||
// the languages on Glosbe which are in ISO 639-2. "Chinese Mandarin" ("cmn") for example
|
||||
// is not supported, but "Chinese" ("zho") is.
|
||||
for (l in languages) {
|
||||
val locale = Locale(l)
|
||||
addLanguage(locale.displayLanguage, locale.isO3Language)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/MainLayoutInTranslationActivity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" />
|
||||
|
||||
<include layout="@layout/progress_bar_layout"/>
|
||||
|
||||
</FrameLayout>
|
@ -1,3 +0,0 @@
|
||||
<menu>
|
||||
|
||||
</menu>
|
@ -22,22 +22,8 @@
|
||||
<string name="multimedia_editor_popup_cloze">Cloze deletion</string>
|
||||
<string name="multimedia_editor_popup_clear_field">Clear field</string>
|
||||
|
||||
<!-- Translation activity (Glosbe) -->
|
||||
<string name="multimedia_editor_trans_poweredglosbe">Powered by glosbe.com</string>
|
||||
<!-- these are like translate f r o m and t o some othe languages -->
|
||||
<string name="multimedia_editor_trans_from">From</string>
|
||||
<string name="multimedia_editor_trans_to">To</string>
|
||||
<!-- imperative for the button title -->
|
||||
<!-- TODO this string should be in dialogs.xml with the other help_item_support_* strings -->
|
||||
<string name="multimedia_editor_trans_translate">Translate</string>
|
||||
<!-- waiting message -->
|
||||
<string name="multimedia_editor_trans_translating_online">Translating online</string>
|
||||
<!-- pick the right translation imperative -->
|
||||
<string name="multimedia_editor_trans_pick_translation">Pick translation</string>
|
||||
<!-- from controller -->
|
||||
<!-- dialog title to ask for translation source -->
|
||||
<string name="multimedia_editor_trans_pick_translation_source">Pick dictionary</string>
|
||||
<!-- dialog asking to install ColorDict -->
|
||||
<string name="multimedia_editor_trans_install_color_dict">Install ColorDict first</string>
|
||||
|
||||
<!-- Pronunciation activity (Beolingus) -->
|
||||
<string name="multimedia_editor_pron_load">Load</string>
|
||||
@ -57,14 +43,11 @@
|
||||
|
||||
<!-- Text field editing -->
|
||||
<!-- buttons -->
|
||||
<string name="multimedia_editor_text_field_editing_search_label">Search for:</string>
|
||||
<string name="multimedia_editor_text_field_editing_say">Pronunciation</string>
|
||||
<string name="multimedia_editor_text_field_editing_clear">Clear</string>
|
||||
<string name="multimedia_editor_text_field_editing_clone">Clone from</string>
|
||||
<string name="multimedia_editor_text_field_editing_translate" comment="Label of a button opening the translation activity">Translation</string>
|
||||
<!-- message to user, when there is no text or many words, but the user tries something -->
|
||||
<string name="multimedia_editor_text_field_editing_no_text">Input some text first</string>
|
||||
<string name="multimedia_editor_text_field_editing_many_words">Dictionary usually expects one word</string>
|
||||
<!-- message when cloning -->
|
||||
<string name="multimedia_editor_text_field_editing_clone_source">Take from</string>
|
||||
|
||||
@ -88,7 +71,6 @@
|
||||
<string name="multimedia_editor_error_word_not_found">The word was not found</string>
|
||||
|
||||
<!-- failure when contacting glosbe or similar -->
|
||||
<string name="multimedia_editor_trans_getting_failure">Getting translation failed</string>
|
||||
<string name="multimedia_editor_searching_word">Searching the word</string>
|
||||
|
||||
<!-- General -->
|
||||
@ -109,9 +91,8 @@
|
||||
<!-- Activity titles -->
|
||||
|
||||
<string name="title_activity_edit_text" comment="Name of the window allowing to edit field. This text can not be seen in AnkiDroid directly.">Editing field</string>
|
||||
<string name="title_activity_translation" comment="Name of the window allowing to translate. This text can not be seen in AnkiDroid directly.">Translation</string>
|
||||
|
||||
<!-- Network failure -->
|
||||
<!-- Network failure -->
|
||||
<string name="network_no_connection">No connection</string>
|
||||
|
||||
<!-- Crop function-->
|
||||
|
@ -19,7 +19,6 @@ import android.app.Activity
|
||||
import android.os.Looper.getMainLooper
|
||||
import com.canhub.cropper.CropImageActivity
|
||||
import com.ichi2.anki.multimediacard.activity.LoadPronunciationActivity
|
||||
import com.ichi2.anki.multimediacard.activity.TranslationActivity
|
||||
import com.ichi2.testutils.ActivityList
|
||||
import com.ichi2.testutils.ActivityList.ActivityLaunchParam
|
||||
import com.ichi2.testutils.EmptyApplication
|
||||
@ -58,7 +57,6 @@ class ActivityStartupUnderBackupTest : RobolectricTest() {
|
||||
notYetHandled(VideoPlayer::class.java.simpleName, "Not working (or implemented) - inherits from Activity")
|
||||
notYetHandled(LoadPronunciationActivity::class.java.simpleName, "Not working (or implemented) - inherits from Activity")
|
||||
notYetHandled(Preferences::class.java.simpleName, "Not working (or implemented) - inherits from AppCompatPreferenceActivity")
|
||||
notYetHandled(TranslationActivity::class.java.simpleName, "Not working (or implemented) - inherits from FragmentActivity")
|
||||
notYetHandled(DeckOptions::class.java.simpleName, "Not working (or implemented) - inherits from AppCompatPreferenceActivity")
|
||||
notYetHandled(FilteredDeckOptions::class.java.simpleName, "Not working (or implemented) - inherits from AppCompatPreferenceActivity")
|
||||
}
|
||||
|
@ -45,7 +45,6 @@ import com.ichi2.anki.StudyOptionsActivity;
|
||||
import com.ichi2.anki.VideoPlayer;
|
||||
import com.ichi2.anki.multimediacard.activity.LoadPronunciationActivity;
|
||||
import com.ichi2.anki.multimediacard.activity.MultimediaEditFieldActivity;
|
||||
import com.ichi2.anki.multimediacard.activity.TranslationActivity;
|
||||
import com.ichi2.anki.services.ReminderService;
|
||||
|
||||
import org.robolectric.Robolectric;
|
||||
@ -91,7 +90,6 @@ public class ActivityList {
|
||||
get(Previewer.class),
|
||||
get(CardTemplatePreviewer.class),
|
||||
get(MultimediaEditFieldActivity.class),
|
||||
get(TranslationActivity.class),
|
||||
get(LoadPronunciationActivity.class),
|
||||
get(CardInfo.class),
|
||||
get(CardTemplateEditor.class, ActivityList::intentForCardTemplateEditor),
|
||||
|
Loading…
Reference in New Issue
Block a user