mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
refactoring
This commit is contained in:
parent
41d4df3e98
commit
ba229dbccd
1 changed files with 19 additions and 13 deletions
|
@ -153,25 +153,16 @@ public abstract class DictionaryUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openWordInDictionary(Activity activity, ZLTextWordRegion region) {
|
public static void openTextInDictionary(Activity activity, String text, int selectionTop, int selectionBottom) {
|
||||||
String text = region.Word.toString();
|
|
||||||
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 PackageInfo info = getCurrentDictionaryInfo();
|
final PackageInfo info = getCurrentDictionaryInfo();
|
||||||
final Intent intent = getDictionaryIntent(info, text.substring(start, end));
|
final Intent intent = getDictionaryIntent(info, text);
|
||||||
try {
|
try {
|
||||||
if ("ColorDict".equals(info.Id)) {
|
if ("ColorDict".equals(info.Id)) {
|
||||||
final DisplayMetrics metrics = new DisplayMetrics();
|
final DisplayMetrics metrics = new DisplayMetrics();
|
||||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||||
final int screenHeight = metrics.heightPixels;
|
final int screenHeight = metrics.heightPixels;
|
||||||
final int topSpace = region.getTop();
|
final int topSpace = selectionTop;
|
||||||
final int bottomSpace = metrics.heightPixels - region.getBottom();
|
final int bottomSpace = metrics.heightPixels - selectionBottom;
|
||||||
final boolean showAtBottom = bottomSpace >= topSpace;
|
final boolean showAtBottom = bottomSpace >= topSpace;
|
||||||
final int space = (showAtBottom ? bottomSpace : topSpace) - 20;
|
final int space = (showAtBottom ? bottomSpace : topSpace) - 20;
|
||||||
final int maxHeight = Math.min(400, screenHeight * 2 / 3);
|
final int maxHeight = Math.min(400, screenHeight * 2 / 3);
|
||||||
|
@ -187,6 +178,21 @@ public abstract class DictionaryUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void openWordInDictionary(Activity activity, ZLTextWordRegion region) {
|
||||||
|
String text = region.Word.toString();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
openTextInDictionary(
|
||||||
|
activity, text.substring(start, end), region.getTop(), region.getBottom()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static void installDictionaryIfNotInstalled(final Activity activity) {
|
public static void installDictionaryIfNotInstalled(final Activity activity) {
|
||||||
if (PackageUtil.canBeStarted(activity, getDictionaryIntent("test"), false)) {
|
if (PackageUtil.canBeStarted(activity, getDictionaryIntent("test"), false)) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue