com.paragon.open.dictionary.api
Class Dictionary

java.lang.Object
  extended by com.paragon.open.dictionary.api.Dictionary

public final class Dictionary
extends java.lang.Object

Class to work with the dictionary.

Allows to get the translation of the words. See getTranslationAsText() and getTranslationAsImage() below.

Also allows to show the translation of the words in the dictionary activity. See showTranslation(String) and showTranslation(String, Activity, int) below.

Author:
Sergey Solomatin (Sergey_Solomatin@penreader.com)

Nested Class Summary
static interface Dictionary.TranslateAsImageListener
          Callback interface for the translation in image format requests.
static interface Dictionary.TranslateAsTextListener
          Callback interface for the translation in text format requests.
 
Field Summary
static int TRANSLATION_RESULT_CODE_DATABASE_IS_UNAVAILABLE
          The dictionary database is not avaiable.
static int TRANSLATION_RESULT_CODE_EXACT_MATCH
          The specified word was found and its translation was shown.
static int TRANSLATION_RESULT_CODE_NO_MATCH
          The specified word was not found and similar words were not found too.
static int TRANSLATION_RESULT_CODE_PARTIALLY_MATCH
          This is usual for strings containing several words separated by spaces.
static int TRANSLATION_RESULT_CODE_SIMILAR_WORDS
          The specified word was not found but similar words are found.
 
Method Summary
 boolean equals(java.lang.Object o)
           
 android.graphics.drawable.Drawable getApplicationIcon()
          Get an icon of the dictionary application.
 java.lang.CharSequence getApplicationLabel()
          Get a label of the dictionary appliction.
 java.lang.String getApplicationPackageName()
          Get a package name of the dictionary application.
 java.lang.String getAuthorName()
          Get an author's name of the dictionary.
 java.lang.String getAuthorName(java.util.Locale loc)
          Get an author's name of the dictionary for a specific locale.
 java.lang.String getAuthorWeb()
          Get an author's web address of the dictionary.
 java.lang.String getAuthorWeb(java.util.Locale loc)
          Get an author's web address of the dictionary for a specific locale.
 Direction getDirection()
          Get translation direction of the dictionary.
 java.lang.String getLanguageName()
          Get a "from" language name of the dictionary.
 java.lang.String getLanguageName(java.util.Locale loc)
          Get a "to" language name of the dictionary for a specific locale.
 java.lang.String getLanguagesPairName()
          Get a name of the languages pair of the dictionary.
 java.lang.String getLanguagesPairName(java.util.Locale loc)
          Get a name of the languages pair of the dictionary for a specific locale.
 java.lang.String getLanguagesPairNameShort()
          Get a short name of the languages pair of the dictionary.
 java.lang.String getLanguagesPairNameShort(java.util.Locale loc)
          Get a short name of the languages pair of the dictionary for a specific locale.
 Morphology getMorphology()
          Get a morphology module of the dictionary.
 java.lang.String getName()
          Get a name of the dictionary.
 java.lang.String getName(java.util.Locale loc)
          Get the name of the dictionary for a specific locale.
 java.lang.String getNameShort()
          Get a short name of the dictionary.
 java.lang.String getNameShort(java.util.Locale loc)
          Get a short name of the dictionary for a specific locale.
 Dictionary getPairDictionary()
          Get pair dictionary.
 java.lang.String getProductName()
          Get a product name of the dictionary.
 java.lang.String getProductName(java.util.Locale loc)
          Get a product name of the dictionary for a specific locale.
 void getTranslationAsImage(java.lang.String word, TranslateMode mode, int width, int height, Dictionary.TranslateAsImageListener listener)
          Async method to get translation of the word as image.
 void getTranslationAsText(java.lang.String word, TranslateMode mode, TranslateFormat format, Dictionary.TranslateAsTextListener listener)
          Async method to get translation of the word as text.
 java.lang.String getUID()
          Get the UID property of the dictionary.
 java.lang.String getVersion()
          Get a version of the dictionary.
 int getWordsCount()
          Get articles count of the dictionary.
 int hashCode()
           
 boolean hasMorphology()
          Checks if the dictionary has a morphology module.
 boolean hasPairDictionary()
          Checks if the dictionary has a pair dictionary.
 boolean isRTL()
          Get a RTL (right to left) property of the dictionary.
 boolean isTranslationAsImageSupported()
          Checks if translation as image is supported.
 boolean isTranslationAsTextSupported()
          Checks if translation as text is supported.
 void showTranslation(java.lang.String word)
          Launch dictionary activity that will show translation to the user.
 void showTranslation(java.lang.String word, android.app.Activity parent, int requestCode)
          Launch dictionary activity that shows translation to the user.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TRANSLATION_RESULT_CODE_EXACT_MATCH

public static final int TRANSLATION_RESULT_CODE_EXACT_MATCH
The specified word was found and its translation was shown.

See Also:
Constant Field Values

TRANSLATION_RESULT_CODE_DATABASE_IS_UNAVAILABLE

public static final int TRANSLATION_RESULT_CODE_DATABASE_IS_UNAVAILABLE
The dictionary database is not avaiable. The user will see the toast with message.

See Also:
Constant Field Values

TRANSLATION_RESULT_CODE_PARTIALLY_MATCH

public static final int TRANSLATION_RESULT_CODE_PARTIALLY_MATCH
This is usual for strings containing several words separated by spaces. This answer means that some of these words can be translated.

See Also:
Constant Field Values

TRANSLATION_RESULT_CODE_SIMILAR_WORDS

public static final int TRANSLATION_RESULT_CODE_SIMILAR_WORDS
The specified word was not found but similar words are found. The user will see a list of similar words with the ability of their translation.

See Also:
Constant Field Values

TRANSLATION_RESULT_CODE_NO_MATCH

public static final int TRANSLATION_RESULT_CODE_NO_MATCH
The specified word was not found and similar words were not found too. The user will see a toast with a message.

See Also:
Constant Field Values
Method Detail

getTranslationAsText

public void getTranslationAsText(java.lang.String word,
                                 TranslateMode mode,
                                 TranslateFormat format,
                                 Dictionary.TranslateAsTextListener listener)
Async method to get translation of the word as text. Check isTranslationAsTextSupported() before use this method.

Parameters:
word -
mode - translate mode
format - translate format
listener - callback interface to handle the result or error
Throws:
java.lang.IllegalArgumentException

getTranslationAsImage

public void getTranslationAsImage(java.lang.String word,
                                  TranslateMode mode,
                                  int width,
                                  int height,
                                  Dictionary.TranslateAsImageListener listener)
Async method to get translation of the word as image. Check isTranslationAsImageSupported() before use this method.

Parameters:
word -
mode - translate mode
width - width of the result image
height - height of the result image
listener - callback interface to handle the result or error
Throws:
java.lang.IllegalArgumentException

isTranslationAsTextSupported

public boolean isTranslationAsTextSupported()
Checks if translation as text is supported.

Returns:
true if translation as text is supported

isTranslationAsImageSupported

public boolean isTranslationAsImageSupported()
Checks if translation as image is supported.

Returns:
true if translation as image is supported

showTranslation

public void showTranslation(java.lang.String word)
Launch dictionary activity that will show translation to the user.

Parameters:
word - one word or several words delimited by comma or space

showTranslation

public void showTranslation(java.lang.String word,
                            android.app.Activity parent,
                            int requestCode)
Launch dictionary activity that shows translation to the user. This method will return a result code of translation that you can process in Activity.onActivityResult() method.

Parameters:
word - one word or several words delimited by comma or space
parent - activity that will process a result code of translation
requestCode - request code used for Activity.startActivityForResult() method
See Also:
TRANSLATION_RESULT_CODE_DATABASE_IS_UNAVAILABLE, TRANSLATION_RESULT_CODE_PARTIALLY_MATCH, TRANSLATION_RESULT_CODE_SIMILAR_WORDS, TRANSLATION_RESULT_CODE_NO_MATCH

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getUID

public java.lang.String getUID()
Get the UID property of the dictionary.

Returns:
UID

getDirection

public Direction getDirection()
Get translation direction of the dictionary.

Returns:
direction

hasPairDictionary

public boolean hasPairDictionary()
Checks if the dictionary has a pair dictionary. It's true if dictionary is bidirectional. Pair dictionary has translation direction opposite to this dictionary.

Returns:
true if has a pair dictionary

getPairDictionary

public Dictionary getPairDictionary()
Get pair dictionary. Pair dictionary has translation direction opposite to this dictionary.

Returns:
pair dictionary

getWordsCount

public int getWordsCount()
Get articles count of the dictionary.

Returns:
words count

getVersion

public java.lang.String getVersion()
Get a version of the dictionary.

Returns:
version

isRTL

public boolean isRTL()
Get a RTL (right to left) property of the dictionary.

Returns:
true is it an RTL dictionary

hasMorphology

public boolean hasMorphology()
Checks if the dictionary has a morphology module.

Returns:
true if the dictionary has a morphology module

getMorphology

public Morphology getMorphology()
Get a morphology module of the dictionary.

Returns:
morphology module or null if the dictionary has no morphology module

getName

public java.lang.String getName()
Get a name of the dictionary.

Returns:
name

getName

public java.lang.String getName(java.util.Locale loc)
Get the name of the dictionary for a specific locale.

Parameters:
loc - locale
Returns:
name

getNameShort

public java.lang.String getNameShort()
Get a short name of the dictionary.

Returns:
short name

getNameShort

public java.lang.String getNameShort(java.util.Locale loc)
Get a short name of the dictionary for a specific locale.

Parameters:
loc - locale
Returns:
short name

getLanguageName

public java.lang.String getLanguageName()
Get a "from" language name of the dictionary.

Returns:
language name

getLanguageName

public java.lang.String getLanguageName(java.util.Locale loc)
Get a "to" language name of the dictionary for a specific locale.

Parameters:
loc - locale
Returns:
language name

getLanguagesPairName

public java.lang.String getLanguagesPairName()
Get a name of the languages pair of the dictionary.

Returns:
name of the languages pair

getLanguagesPairName

public java.lang.String getLanguagesPairName(java.util.Locale loc)
Get a name of the languages pair of the dictionary for a specific locale.

Parameters:
loc - locale
Returns:
name of the languages pair

getLanguagesPairNameShort

public java.lang.String getLanguagesPairNameShort()
Get a short name of the languages pair of the dictionary.

Returns:
short name of the languages pair

getLanguagesPairNameShort

public java.lang.String getLanguagesPairNameShort(java.util.Locale loc)
Get a short name of the languages pair of the dictionary for a specific locale.

Parameters:
loc - locale
Returns:
short name of the languages pair

getAuthorName

public java.lang.String getAuthorName()
Get an author's name of the dictionary.

Returns:
author name

getAuthorName

public java.lang.String getAuthorName(java.util.Locale loc)
Get an author's name of the dictionary for a specific locale.

Parameters:
loc - locale
Returns:
author name

getAuthorWeb

public java.lang.String getAuthorWeb()
Get an author's web address of the dictionary.

Returns:
author web address

getAuthorWeb

public java.lang.String getAuthorWeb(java.util.Locale loc)
Get an author's web address of the dictionary for a specific locale.

Parameters:
loc - locale
Returns:
author web address

getProductName

public java.lang.String getProductName()
Get a product name of the dictionary.

Returns:
product name

getProductName

public java.lang.String getProductName(java.util.Locale loc)
Get a product name of the dictionary for a specific locale.

Parameters:
loc - locale
Returns:
product name

getApplicationPackageName

public java.lang.String getApplicationPackageName()
Get a package name of the dictionary application.

Returns:
package name

getApplicationIcon

public android.graphics.drawable.Drawable getApplicationIcon()
Get an icon of the dictionary application.

Returns:
application icon or null if any error occurs while retrieving the icon

getApplicationLabel

public java.lang.CharSequence getApplicationLabel()
Get a label of the dictionary appliction.

Returns:
application label or null if any error occurs while retrieving the label