import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
-import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.BaseAdapter;
import android.widget.Button;
import com.hughes.android.dictionary.engine.TransliteratorManager;
import com.hughes.android.util.IntentLauncher;
import com.hughes.android.util.NonLinkClickableSpan;
+import com.hughes.util.StringUtil;
import java.io.File;
import java.io.FileWriter;
TextToSpeech textToSpeech;
volatile boolean ttsReady;
+
+ int textColorFg = Color.BLACK;
+
private final Executor searchExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
@Override
application = (DictionaryApplication) getApplication();
theme = application.getSelectedTheme();
+ textColorFg = getResources().getColor(theme.tokenRowFgColor);
final Intent intent = getIntent();
dictFile = new File(intent.getStringExtra(C.DICT_FILE));
updateTTSLanuage();
}
});
-
+
try {
final String name = application.getDictionaryName(dictFile.getName());
this.setTitle("QuickDic: " + name);
onUpDownButton(false);
}
});
+ upButton.setVisibility(PreferenceManager.getDefaultSharedPreferences(this)
+ .getBoolean(getString(R.string.showPrevNextButtonsKey), true) ? View.VISIBLE
+ : View.GONE);
+ downButton.setVisibility(PreferenceManager.getDefaultSharedPreferences(this)
+ .getBoolean(getString(R.string.showPrevNextButtonsKey), true) ? View.VISIBLE
+ : View.GONE);
// getListView().setOnItemSelectedListener(new ListView.OnItemSelectedListener() {
// @Override
protected void onResume() {
Log.d(LOG, "onResume");
super.onResume();
- if (PreferenceActivity.prefsMightHaveChanged) {
- PreferenceActivity.prefsMightHaveChanged = false;
+ if (SettingsActivity.settingsMightHaveChanged) {
+ SettingsActivity.settingsMightHaveChanged = false;
finish();
startActivity(getIntent());
}
@Override
public void run() {
Log.d(LOG, "Trying to show soft keyboard.");
+ final boolean searchTextHadFocus = searchText.hasFocus();
+ searchText.requestFocus();
final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
manager.showSoftInput(searchText, InputMethodManager.SHOW_IMPLICIT);
+ if (!searchTextHadFocus) {
+ defocusSearchText();
+ }
}}, 100);
}
}
private void updateTTSLanuage() {
- if (!ttsReady) {
+ if (!ttsReady || index == null || textToSpeech == null) {
+ Log.d(LOG, "Can't updateTTSLanguage.");
return;
}
final Locale locale = new Locale(index.sortLanguage.getIsoCode());
Log.d(LOG, "Setting TTS locale to: " + locale);
final int ttsResult = textToSpeech.setLanguage(locale);
- if (ttsResult != TextToSpeech.LANG_AVAILABLE || ttsResult != TextToSpeech.LANG_COUNTRY_AVAILABLE) {
+ if (ttsResult != TextToSpeech.LANG_AVAILABLE ||
+ ttsResult != TextToSpeech.LANG_COUNTRY_AVAILABLE) {
Log.e(LOG, "TTS not available in this language: ttsResult=" + ttsResult);
}
}
}
});
+ final MenuItem share = menu.add("Share");
+ share.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+ public boolean onMenuItemClick(MenuItem item) {
+ Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
+ shareIntent.setType("text/plain");
+ shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, row.getTokenRow(true).getToken());
+ shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, row.getRawText(saveOnlyFirstSubentry));
+ startActivity(shareIntent);
+ return false;
+ }
+ });
+
final MenuItem copy = menu.add(android.R.string.copy);
copy.setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
boolean done = false;
SearchOperation(final String searchText, final Index index) {
- this.searchText = searchText.trim();
+ this.searchText = StringUtil.normalizeWhitespace(searchText);
this.index = index;
}
searchResult = index.findInsertionPoint(searchText, interrupted);
} else {
searchTokens = Arrays.asList(searchTokenArray);
- multiWordSearchResult = index.multiWordSearch(searchTokens, interrupted);
+ multiWordSearchResult = index.multiWordSearch(searchText, searchTokens, interrupted);
}
Log.d(LOG,
"searchText=" + searchText + ", searchDuration="
textView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- final String html = HtmlEntry.htmlBody(htmlEntries, index.shortName);
+ String html = HtmlEntry.htmlBody(htmlEntries, index.shortName);
+ //Log.d(LOG, "html=" + html);
startActivityForResult(
HtmlDisplayActivity.getHtmlIntent(String.format(
"<html><head></head><body>%s</body></html>", html),
}
static final Pattern CHAR_DASH = Pattern.compile("['\\p{L}\\p{M}\\p{N}]+");
-
+
private void createTokenLinkSpans(final TextView textView, final Spannable spannable,
final String text) {
// Saw from the source code that LinkMovementMethod sets the selection!
textView.setMovementMethod(LinkMovementMethod.getInstance());
final Matcher matcher = CHAR_DASH.matcher(text);
while (matcher.find()) {
- spannable.setSpan(new NonLinkClickableSpan(), matcher.start(), matcher.end(),
+ spannable.setSpan(new NonLinkClickableSpan(textColorFg), matcher.start(), matcher.end(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
}