+ if (dictFilename == null && intent.getStringExtra(C.SEARCH_TOKEN) != null) {
+ final List<DictionaryInfo> dics = application.getDictionariesOnDevice(null);
+ final String search = intent.getStringExtra(C.SEARCH_TOKEN);
+ String bestFname = null;
+ String bestIndex = null;
+ int bestMatchLen = 2; // ignore shorter matches
+ AtomicBoolean dummy = new AtomicBoolean();
+ for (int i = 0; dictFilename == null && i < dics.size(); ++i) {
+ try {
+ Log.d(LOG, "Checking dictionary " + dics.get(i).uncompressedFilename);
+ final File dictfile = application.getPath(dics.get(i).uncompressedFilename);
+ Dictionary dic = new Dictionary(new RandomAccessFile(dictfile, "r").getChannel());
+ for (int j = 0; j < dic.indices.size(); ++j) {
+ Index idx = dic.indices.get(j);
+ Log.d(LOG, "Checking index " + idx.shortName);
+ if (idx.findExact(search) != null) {
+ Log.d(LOG, "Found exact match");
+ dictFilename = dictfile.toString();
+ intent.putExtra(C.INDEX_SHORT_NAME, idx.shortName);
+ break;
+ }
+ int matchLen = getMatchLen(search, idx.findInsertionPoint(search, dummy));
+ Log.d(LOG, "Found partial match length " + matchLen);
+ if (matchLen > bestMatchLen) {
+ bestFname = dictfile.toString();
+ bestIndex = idx.shortName;
+ bestMatchLen = matchLen;
+ }
+ }
+ } catch (Exception e) {}
+ }
+ if (dictFilename == null && bestFname != null) {
+ dictFilename = bestFname;
+ intent.putExtra(C.INDEX_SHORT_NAME, bestIndex);
+ }
+ }
+
+ if (dictFilename == null) {
+ if (!isFinishing())
+ Toast.makeText(this, getString(R.string.no_dict_file), Toast.LENGTH_LONG).show();
+ startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext()));