Android Open Source - android-unispeech Translator Callback






From Project

Back to project page android-unispeech.

License

The source code is released under:

Apache License

If you think the Android project android-unispeech listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.github.unispeech.recognition;
//from www .  j av  a2  s.c  o m
import android.text.Html;
import android.util.Log;

import com.github.unispeech.R;
import com.rookery.web_api_translate.GoogleTranslator;
import com.rookery.web_api_translate.type.Language;
import com.rookery.web_api_translate.type.TranslateError;

/**
* Created by javier.romero on 2/8/14.
*/
class TranslatorCallback implements GoogleTranslator.Callback {

    private static final String TAG = TranslatorCallback.class.getSimpleName();
    // FIXME: Make weak reference
    private final RecognitionActivity mActivity;
    private final SpeechData mSpeechData;

    public TranslatorCallback(RecognitionActivity activity, SpeechData speechData) {
        mActivity = activity;
        mSpeechData = speechData;
        mActivity.setStatus(R.string.recog_translating);
    }

    @Override
    public void onSuccess(Language detected_lang, String translated_text) {
        Log.v(TAG, "GoogleTranslator: onSuccess: from " + detected_lang + " '" + translated_text + "'");

        // decode html: http://stackoverflow.com/questions/2918920/decode-html-entities-in-android
        translated_text = Html.fromHtml(Html.fromHtml(translated_text).toString()).toString();

        mSpeechData.setTranslatedText(translated_text);
        mActivity.updateSpeechData(mSpeechData);
        mActivity.stopIndeterminate();
        mActivity.setStatus(R.string.recog_tap_and_hold);
    }

    @Override
    public void onFailed(TranslateError e) {
        Log.e(TAG, "GoogleTranslator: onFailed", e);
        mActivity.stopIndeterminate();
        mActivity.setStatus(e.getMessage());
    }
}




Java Source Code List

com.github.unispeech.App.java
com.github.unispeech.languageselect.BaseLanguageSelectActivity.java
com.github.unispeech.languageselect.SupportedSttLanguage.java
com.github.unispeech.languageselect.TheirLanguageSelectActivity.java
com.github.unispeech.languageselect.YourLanguageSelectActivity.java
com.github.unispeech.recognition.RecognitionActivity.java
com.github.unispeech.recognition.SpeechAdapter.java
com.github.unispeech.recognition.SpeechData.java
com.github.unispeech.recognition.TranslatorCallback.java