mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 02:09:35 +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) {
|
||||
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;
|
||||
}
|
||||
|
||||
public static void openTextInDictionary(Activity activity, String text, int selectionTop, int selectionBottom) {
|
||||
final PackageInfo info = getCurrentDictionaryInfo();
|
||||
final Intent intent = getDictionaryIntent(info, text.substring(start, end));
|
||||
final Intent intent = getDictionaryIntent(info, text);
|
||||
try {
|
||||
if ("ColorDict".equals(info.Id)) {
|
||||
final DisplayMetrics metrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
final int screenHeight = metrics.heightPixels;
|
||||
final int topSpace = region.getTop();
|
||||
final int bottomSpace = metrics.heightPixels - region.getBottom();
|
||||
final int topSpace = selectionTop;
|
||||
final int bottomSpace = metrics.heightPixels - selectionBottom;
|
||||
final boolean showAtBottom = bottomSpace >= topSpace;
|
||||
final int space = (showAtBottom ? bottomSpace : topSpace) - 20;
|
||||
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) {
|
||||
if (PackageUtil.canBeStarted(activity, getDictionaryIntent("test"), false)) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue