From ba229dbccdf9ca5b089560a19f67f44b866c26e3 Mon Sep 17 00:00:00 2001 From: Nikolay Pultsin Date: Sat, 21 May 2011 18:40:13 +0100 Subject: [PATCH] refactoring --- .../android/fbreader/DictionaryUtil.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/org/geometerplus/android/fbreader/DictionaryUtil.java b/src/org/geometerplus/android/fbreader/DictionaryUtil.java index b05b1f8ab..d66098669 100644 --- a/src/org/geometerplus/android/fbreader/DictionaryUtil.java +++ b/src/org/geometerplus/android/fbreader/DictionaryUtil.java @@ -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;