static final String DICTIONARY_CONFIGS = "dictionaryConfigs2";
- static final String DICT_FILE = "dictFile";
- static final String INDEX_INDEX = "indexIndex";
- static final String SEARCH_TOKEN = "searchToken";
- static final String CAN_AUTO_LAUNCH_DICT = "canAutoLaunch";
+ public static final String DICT_FILE = "dictFile";
+ public static final String INDEX_INDEX = "indexIndex";
+ public static final String SEARCH_TOKEN = "searchToken";
+ public static final String CAN_AUTO_LAUNCH_DICT = "canAutoLaunch";
public static final String SHOW_LOCAL = "showLocal";
public static final String THANKS_FOR_UPDATING_VERSION = "thanksForUpdatingVersion";
static final String LOG = "QuickDic";
- private String initialSearchText;
-
DictionaryApplication application;
File dictFile = null;
finish();
startActivity(getIntent());
}
- if (initialSearchText != null) {
- setSearchText(initialSearchText, true);
- }
showKeyboard();
}
protected void onPause() {
super.onPause();
}
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent result) {
+ super.onActivityResult(requestCode, resultCode, result);
+ if (result != null && result.hasExtra(C.SEARCH_TOKEN)) {
+ Log.d(LOG, "onActivityResult: " + result.toString());
+ jumpToTextFromHyperLink(result.getStringExtra(C.SEARCH_TOKEN), indexIndex);
+ }
+ }
private static void setDictionaryPrefs(final Context context, final File dictFile,
final int indexIndex, final String searchToken) {
dialog.show();
}
- private void changeIndexGetFocusAndResearch(final int newIndex) {
+ private void changeIndexGetFocusAndResearch(int newIndex) {
+ Log.d(LOG, "Changing index to: " + newIndex);
+ if (newIndex == -1) {
+ Log.e(LOG, "Invalid index.");
+ newIndex = 0;
+ }
indexIndex = newIndex;
index = dictionary.indices.get(indexIndex);
indexAdapter = new IndexAdapter(index);
selectedSpannableText));
searchForSelection.setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
- int indexToUse = -1;
- for (int i = 0; i < dictionary.indices.size(); ++i) {
- final Index index = dictionary.indices.get(i);
- if (indexPrepFinished) {
- System.out.println("Doing index lookup: on " + selectedText);
- final IndexEntry indexEntry = index.findExact(selectedText);
- if (indexEntry != null) {
- final TokenRow tokenRow = index.rows.get(indexEntry.startRow)
- .getTokenRow(false);
- if (tokenRow != null && tokenRow.hasMainEntry) {
- indexToUse = i;
- break;
- }
- }
- } else {
- Log.w(LOG, "Skipping findExact on index " + index.shortName);
- }
- }
- if (indexToUse == -1) {
- indexToUse = selectedSpannableIndex;
- }
- final boolean changeIndex = indexIndex != indexToUse;
- // If we're not changing index, we have to trigger search:
- setSearchText(selectedText, !changeIndex);
- if (changeIndex) {
- changeIndexGetFocusAndResearch(indexToUse);
- }
- // Give focus back to list view because typing is done.
- getListView().requestFocus();
+ jumpToTextFromHyperLink(selectedText, selectedSpannableIndex);
return false;
}
});
}
});
}
-
+ }
+
+ private void jumpToTextFromHyperLink(final String selectedText, final int defaultIndexToUse) {
+ int indexToUse = -1;
+ for (int i = 0; i < dictionary.indices.size(); ++i) {
+ final Index index = dictionary.indices.get(i);
+ if (indexPrepFinished) {
+ System.out.println("Doing index lookup: on " + selectedText);
+ final IndexEntry indexEntry = index.findExact(selectedText);
+ if (indexEntry != null) {
+ final TokenRow tokenRow = index.rows.get(indexEntry.startRow)
+ .getTokenRow(false);
+ if (tokenRow != null && tokenRow.hasMainEntry) {
+ indexToUse = i;
+ break;
+ }
+ }
+ } else {
+ Log.w(LOG, "Skipping findExact on index " + index.shortName);
+ }
+ }
+ if (indexToUse == -1) {
+ indexToUse = defaultIndexToUse;
+ }
+ final boolean changeIndex = indexIndex != indexToUse;
+ // If we're not changing index, we have to trigger search:
+ setSearchText(selectedText, !changeIndex);
+ if (changeIndex) {
+ changeIndexGetFocusAndResearch(indexToUse);
+ }
+ // Give focus back to list view because typing is done.
+ getListView().requestFocus();
}
@Override
}
}
}, 20);
-
}
-
+
private final void jumpToRow(final int row) {
+ Log.d(LOG, "jumpToRow: " + row);
setSelection(row);
getListView().setSelected(true);
}
searchFinished(SearchOperation.this);
}
});
+ } else {
+ Log.d(LOG, "interrupted, skipping searchFinished.");
}
} catch (Exception e) {
Log.e(LOG, "Failure during search (can happen during Activity close.");
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- final String html = HtmlEntry.htmlBody(htmlEntries);
- startActivity(HtmlDisplayActivity.getHtmlIntent(String.format(
- "<html><head></head><body>%s</body></html>", html), htmlTextToHighlight, false));
+ final String html = HtmlEntry.htmlBody(htmlEntries, index.shortName);
+ startActivityForResult(
+ HtmlDisplayActivity.getHtmlIntent(String.format("<html><head></head><body>%s</body></html>", html), htmlTextToHighlight, false),
+ 0);
}
});
tableRow.addView(button);
} else {\r
html = getIntent().getStringExtra(HTML);\r
}\r
- final WebView webView = (WebView) findViewById(R.id.webView);\r
+ final MyWebView webView = (MyWebView) findViewById(R.id.webView);\r
webView.loadData(html, "text/html", "utf-8");\r
+ webView.activity = this;\r
\r
final String textToHighlight = getIntent().getStringExtra(TEXT_TO_HIGHLIGHT);\r
if (textToHighlight != null && !"".equals(textToHighlight)) {\r
package com.hughes.android.dictionary;
+import android.app.Activity;
import android.content.Context;
+import android.content.Intent;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.ContextMenu;
import android.webkit.WebView;
+import android.webkit.WebViewClient;
+
+import com.hughes.android.dictionary.engine.HtmlEntry;
public class MyWebView extends WebView {
+
+ static final String LOG = "MyWebView";
+
+ HtmlDisplayActivity activity;
public MyWebView(Context context) {
super(context);
public MyWebView(Context context, AttributeSet attrs) {
super(context, attrs);
+ getSettings().setSupportZoom(true);
+ getSettings().setBuiltInZoomControls(true);
+
+ final WebViewClient webViewClient = new WebViewClient() {
+ @Override
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
+ if (HtmlEntry.isQuickdicUrl(url)) {
+ Log.d(LOG, "Handling Quickdic URL: " + url);
+ final Intent result = new Intent();
+ HtmlEntry.quickdicUrlToIntent(url, result);
+ activity.setResult(Activity.RESULT_OK, result);
+ activity.finish();
+ return true;
+ }
+ // TODO Auto-generated method stub
+ return super.shouldOverrideUrlLoading(view, url);
+ }
+ };
+ setWebViewClient(webViewClient);
}
super.onCreateContextMenu(menu);
}
+
+
+
}
package com.hughes.android.dictionary.engine;
+import android.content.Intent;
+
+import com.hughes.android.dictionary.C;
+import com.hughes.util.StringUtil;
import com.hughes.util.raf.RAFListSerializer;
import com.hughes.util.raf.RAFSerializable;
import com.ibm.icu.text.Transliterator;
public class HtmlEntry extends AbstractEntry implements RAFSerializable<HtmlEntry>, Comparable<HtmlEntry> {
- // Both are HTML escaped already.
+ // Title is not HTML escaped.
public final String title;
public String html;
@Override
public void print(PrintStream out) {
final HtmlEntry entry = getEntry();
- out.println("HtmlEntry (shortened): " + entry.title);
+ out.println("See also HtmlEntry:" + entry.title);
}
@Override
}
return RowMatchType.BAG_OF_WORDS_MATCH;
}
-
}
- public static String htmlBody(final List<HtmlEntry> htmlEntries) {
+ public static String htmlBody(final List<HtmlEntry> htmlEntries, final String indexShortName) {
final StringBuilder result = new StringBuilder();
for (final HtmlEntry htmlEntry : htmlEntries) {
+ final String titleEscaped = StringUtil.escapeToPureHtmlUnicode(htmlEntry.title);
result.append(String.format("<h1><a href=\"%s\">%s</a></h1>\n(%s)\n<p>%s\n",
- htmlEntry.title, htmlEntry.title, htmlEntry.entrySource.name,
+ formatQuickdicUrl(indexShortName, titleEscaped), titleEscaped, htmlEntry.entrySource.name,
htmlEntry.html));
}
return result.toString();
}
+
+ public static String formatQuickdicUrl(final String indexShortName, final String text) {
+ assert !indexShortName.contains(":");
+ return String.format("qd:%s:%s", indexShortName, text);
+ }
+
+ public static boolean isQuickdicUrl(String url) {
+ return url.startsWith("qd:");
+ }
+
+ public static void quickdicUrlToIntent(final String url, final Intent intent) {
+ int firstColon = url.indexOf(":");
+ if (firstColon == -1) return;
+ int secondColon = url.indexOf(":", firstColon + 1);
+ if (secondColon == -1) return;
+ intent.putExtra(C.SEARCH_TOKEN, url.substring(secondColon + 1));
+ }
}
isoCodeToResources.put("LB", new LanguageResources("Luxembourgish", R.string.LB));\r
isoCodeToResources.put("MK", new LanguageResources("Macedonian", R.string.MK));\r
\r
+ isoCodeToResources.put("LO", new LanguageResources("Lao", R.string.LO));\r
+ isoCodeToResources.put("ML", new LanguageResources("Malayalam", R.string.ML));\r
+ isoCodeToResources.put("SL", new LanguageResources("Slovenian", R.string.SL));\r
+ isoCodeToResources.put("TA", new LanguageResources("Tamil", R.string.TA));\r
+\r
// Hack to allow lower-case ISO codes to work:\r
for (final String isoCode : new ArrayList<String>(isoCodeToResources.keySet())) {\r
isoCodeToResources.put(isoCode.toLowerCase(), isoCodeToResources.get(isoCode));\r