1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 18:29:23 +02:00

colordict 3 support

This commit is contained in:
Nikolay Pultsin 2011-01-28 05:25:36 +00:00
parent 93056fa687
commit fb3648b597
5 changed files with 37 additions and 13 deletions

View file

@ -1,3 +1,6 @@
===== 0.99.10 (??? ??, 2011) =====
* ColorDict3 support (floating window)
===== 0.99.6 (Jan 22, 2011) ===== ===== 0.99.6 (Jan 22, 2011) =====
* Wallpaper drawing speed-up * Wallpaper drawing speed-up

View file

@ -24,10 +24,14 @@ import java.util.*;
import android.app.*; import android.app.*;
import android.content.*; import android.content.*;
import android.net.Uri; import android.net.Uri;
import android.util.DisplayMetrics;
import android.view.Gravity;
import org.geometerplus.zlibrary.core.options.ZLStringOption; import org.geometerplus.zlibrary.core.options.ZLStringOption;
import org.geometerplus.zlibrary.core.resources.ZLResource; import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.text.view.ZLTextWordRegion;
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication; import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
import org.geometerplus.android.util.UIUtil; import org.geometerplus.android.util.UIUtil;
@ -58,7 +62,7 @@ public abstract class DictionaryUtil {
"ColorDict", // Id "ColorDict", // Id
null, // Package null, // Package
null, // Class null, // Class
"ColorDict", // Title "ColorDict 3", // Title
ColorDict3.ACTION, ColorDict3.ACTION,
ColorDict3.QUERY, ColorDict3.QUERY,
"%s" "%s"
@ -164,21 +168,14 @@ public abstract class DictionaryUtil {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
text = dictionaryInfo.IntentDataPattern.replace("%s", text); text = dictionaryInfo.IntentDataPattern.replace("%s", text);
if (dictionaryInfo.IntentKey != null) { if (dictionaryInfo.IntentKey != null) {
intent.putExtra(ColorDict3.HEIGHT, 300);
intent.putExtra(ColorDict3.GRAVITY, android.view.Gravity.BOTTOM);
final ZLAndroidApplication application = ZLAndroidApplication.Instance();
intent.putExtra(ColorDict3.FULLSCREEN, !application.ShowStatusBarOption.getValue());
return intent.putExtra(dictionaryInfo.IntentKey, text); return intent.putExtra(dictionaryInfo.IntentKey, text);
} else { } else {
return intent.setData(Uri.parse(text)); return intent.setData(Uri.parse(text));
} }
} }
public static void openWordInDictionary(Activity activity, String text) { public static void openWordInDictionary(Activity activity, ZLTextWordRegion region) {
if (text == null) { String text = region.Word.toString();
return;
}
int start = 0; int start = 0;
int end = text.length(); int end = text.length();
for (; start < end && !Character.isLetterOrDigit(text.charAt(start)); ++start); for (; start < end && !Character.isLetterOrDigit(text.charAt(start)); ++start);
@ -187,8 +184,24 @@ public abstract class DictionaryUtil {
return; return;
} }
final Intent intent = DictionaryUtil.getDictionaryIntent(text.substring(start, end)); final PackageInfo info = getCurrentDictionaryInfo();
final Intent intent = getDictionaryIntent(info, text.substring(start, end));
try { 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 boolean showAtBottom = bottomSpace >= topSpace;
final int space = (showAtBottom ? bottomSpace : topSpace) - 20;
final int maxHeight = Math.min(400, screenHeight * 2 / 3);
final int minHeight = Math.min(200, screenHeight * 2 / 3);
intent.putExtra(ColorDict3.HEIGHT, Math.max(minHeight, Math.min(maxHeight, space)));
intent.putExtra(ColorDict3.GRAVITY, showAtBottom ? Gravity.BOTTOM : Gravity.TOP);
final ZLAndroidApplication application = ZLAndroidApplication.Instance();
intent.putExtra(ColorDict3.FULLSCREEN, !application.ShowStatusBarOption.getValue());
}
activity.startActivity(intent); activity.startActivity(intent);
} catch(ActivityNotFoundException e){ } catch(ActivityNotFoundException e){
DictionaryUtil.installDictionaryIfNotInstalled(activity); DictionaryUtil.installDictionaryIfNotInstalled(activity);

View file

@ -63,7 +63,7 @@ class ProcessHyperlinkAction extends FBAction {
return; return;
} else if (region instanceof ZLTextWordRegion) { } else if (region instanceof ZLTextWordRegion) {
DictionaryUtil.openWordInDictionary( DictionaryUtil.openWordInDictionary(
myBaseActivity, ((ZLTextWordRegion)region).Word.toString() myBaseActivity, (ZLTextWordRegion)region
); );
} }
} }

View file

@ -42,7 +42,7 @@ class DictionaryPreference extends ZLStringListPreference {
final String[] texts = new String[infos.size()]; final String[] texts = new String[infos.size()];
int index = 0; int index = 0;
for (PackageInfo i : infos) { for (PackageInfo i : infos) {
values[index] = i.Title; values[index] = i.Id;
texts[index] = i.Title; texts[index] = i.Title;
++index; ++index;
} }

View file

@ -60,6 +60,14 @@ public abstract class ZLTextElementRegion {
return myHull; return myHull;
} }
public int getTop() {
return myList.get(myFromIndex).YStart;
}
public int getBottom() {
return myList.get(myToIndex - 1).YEnd;
}
void draw(ZLPaintContext context) { void draw(ZLPaintContext context) {
convexHull().draw(context); convexHull().draw(context);
} }