mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
code cleanup
This commit is contained in:
parent
8006ec5fd0
commit
009821710b
2 changed files with 29 additions and 25 deletions
|
@ -24,6 +24,7 @@ import java.util.*;
|
|||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.SearchManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ComponentName;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
|
@ -50,6 +51,11 @@ public abstract class DictionaryUtil {
|
|||
"com.ngc.fora.ForaDictionary",
|
||||
"Fora Dictionary"
|
||||
));
|
||||
ourDictionaryInfos.add(new PackageInfo(
|
||||
"org.freedictionary",
|
||||
"org.freedictionary.MainActivity",
|
||||
"Free Dictionary . org"
|
||||
));
|
||||
}
|
||||
return ourDictionaryInfos;
|
||||
}
|
||||
|
@ -82,6 +88,27 @@ public abstract class DictionaryUtil {
|
|||
.putExtra(SearchManager.QUERY, text);
|
||||
}
|
||||
|
||||
public static void openWordInDictionary(Activity activity, String text) {
|
||||
if (text == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int start = 0;
|
||||
int end = text.length();
|
||||
for (; start < end && !Character.isLetterOrDigit(text.charAt(start)); ++start);
|
||||
for (; start < end && !Character.isLetterOrDigit(text.charAt(end - 1)); --end);
|
||||
if (start == end) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Intent intent = DictionaryUtil.getDictionaryIntent(text.substring(start, end));
|
||||
try {
|
||||
activity.startActivity(intent);
|
||||
} catch(ActivityNotFoundException e){
|
||||
DictionaryUtil.installDictionaryIfNotInstalled(activity);
|
||||
}
|
||||
}
|
||||
|
||||
public static void installDictionaryIfNotInstalled(final Activity activity) {
|
||||
if (PackageUtil.canBeStarted(activity, getDictionaryIntent("test"))) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue