\r
import com.hughes.android.dictionary.engine.Dictionary;\r
import com.hughes.android.dictionary.engine.Index;\r
+import com.hughes.android.dictionary.engine.Language;\r
import com.hughes.android.dictionary.engine.PairEntry;\r
import com.hughes.android.dictionary.engine.PairEntry.Pair;\r
import com.hughes.android.dictionary.engine.RowBase;\r
\r
public static Intent getIntent(final Context context, final int dictIndex, final int indexIndex, final String searchToken) {\r
setDictionaryPrefs(context, dictIndex, indexIndex, searchToken);\r
- \r
final Intent intent = new Intent();\r
intent.setClassName(DictionaryActivity.class.getPackage().getName(), DictionaryActivity.class.getName());\r
return intent;\r
}\r
+ \r
+ // TODO: Can we trigger an App restart when the preferences activity gets opened?\r
+ // TODO: fix these...\r
+\r
+ @Override\r
+ protected void onSaveInstanceState(final Bundle outState) {\r
+ super.onSaveInstanceState(outState);\r
+ setDictionaryPrefs(this, dictIndex, indexIndex, searchText.getText().toString());\r
+ }\r
\r
public static void setDictionaryPrefs(final Context context,\r
final int dictIndex, final int indexIndex, final String searchToken) {\r
prefs.putString(C.SEARCH_TOKEN, searchToken);\r
prefs.commit();\r
}\r
-\r
+ \r
public static void clearDictionaryPrefs(final Context context) {\r
- final SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(context).edit();\r
+ final SharedPreferences.Editor prefs = PreferenceManager\r
+ .getDefaultSharedPreferences(context).edit();\r
prefs.remove(C.DICT_INDEX);\r
prefs.remove(C.INDEX_INDEX);\r
prefs.remove(C.SEARCH_TOKEN);\r
QuickDicConfig quickDicConfig = PersistentObjectCache.init(\r
this).read(C.DICTIONARY_CONFIGS, QuickDicConfig.class);\r
dictIndex = prefs.getInt(C.DICT_INDEX, 0) ;\r
- final DictionaryConfig dictionaryConfig = quickDicConfig.dictionaryConfigs.get(dictIndex);\r
+ final DictionaryInfo dictionaryConfig = quickDicConfig.dictionaryConfigs.get(dictIndex);\r
this.setTitle("QuickDic: " + dictionaryConfig.name);\r
dictRaf = new RandomAccessFile(dictionaryConfig.localFile, "r");\r
dictionary = new Dictionary(dictRaf); \r
dictRaf = null;\r
}\r
Toast.makeText(this, getString(R.string.invalidDictionary, "", e.getMessage()), Toast.LENGTH_LONG);\r
- startActivity(DictionaryEditActivity.getIntent(dictIndex));\r
+ startActivity(DictionaryManagerActivity.getIntent(this));\r
finish();\r
return;\r
}\r
});\r
\r
for (final Index index : dictionary.indices) {\r
- Log.d(LOG, "Starting collator load for lang=" + index.sortLanguage.getSymbol());\r
+ Log.d(LOG, "Starting collator load for lang=" + index.sortLanguage.getIsoCode());\r
\r
final com.ibm.icu.text.Collator c = index.sortLanguage.getCollator(); \r
if (c.compare("pre-print", "preppy") >= 0) {\r
@Override\r
protected void onResume() {\r
super.onResume();\r
+ if (PreferenceActivity.prefsMightHaveChanged) {\r
+ PreferenceActivity.prefsMightHaveChanged = false;\r
+ finish();\r
+ startActivity(getIntent());\r
+ }\r
}\r
\r
@Override\r
final MenuItem preferences = menu.add(getString(R.string.preferences));\r
preferences.setOnMenuItemClickListener(new OnMenuItemClickListener() {\r
public boolean onMenuItemClick(final MenuItem menuItem) {\r
+ PreferenceActivity.prefsMightHaveChanged = true;\r
startActivity(new Intent(DictionaryActivity.this,\r
PreferenceActivity.class));\r
return false;\r
final MenuItem dictionaryList = menu.add(getString(R.string.dictionaryList));\r
dictionaryList.setOnMenuItemClickListener(new OnMenuItemClickListener() {\r
public boolean onMenuItemClick(final MenuItem menuItem) {\r
- startActivity(DictionaryListActivity.getIntent(DictionaryActivity.this));\r
+ startActivity(DictionaryManagerActivity.getIntent(DictionaryActivity.this));\r
finish();\r
return false;\r
}\r
return true;\r
}\r
if (keyCode == KeyEvent.KEYCODE_BACK) {\r
- Log.d(LOG, "Clearing dictionary prefs.");\r
- DictionaryActivity.clearDictionaryPrefs(this);\r
}\r
if (keyCode == KeyEvent.KEYCODE_ENTER) {\r
-// Log.d(LOG, "Trying to hide soft keyboard.");\r
-// final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);\r
-// manager.hideSoftInputFromWindow(searchText, InputMethodManager.SHOW_FORCED);\r
-\r
+ Log.d(LOG, "Trying to hide soft keyboard.");\r
+ final InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);\r
+ inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);\r
+ return true;\r
}\r
return super.onKeyDown(keyCode, event);\r
}\r
\r
// TODO: color words by gender\r
final Pair pair = entry.pairs.get(r);\r
- final String col1Text = index.swapPairEntries ? pair.lang2 : pair.lang1;\r
+ final String col1Text = Language.fixBidiText(index.swapPairEntries ? pair.lang2 : pair.lang1);\r
column1.setText(col1Text, TextView.BufferType.SPANNABLE);\r
final Spannable col1Spannable = (Spannable) column1.getText();\r
\r
startPos += token.length();\r
}\r
\r
- final String col2Text = index.swapPairEntries ? pair.lang1 : pair.lang2;\r
+ String col2Text = index.swapPairEntries ? pair.lang1 : pair.lang2;\r
+ col2Text = Language.fixBidiText(col2Text);\r
column2.setText(col2Text, TextView.BufferType.NORMAL);\r
\r
column1.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSizeSp);\r
}\r
\r
private View getView(TokenRow row, ViewGroup parent) {\r
- final TextView textView = new TextView(parent.getContext());\r
+ final Context context = parent.getContext();\r
+ final TextView textView = new TextView(context);\r
textView.setText(row.getToken());\r
+ textView.setBackgroundResource(R.drawable.token_row_drawable);\r
+ // Doesn't work:\r
+ //textView.setTextColor(android.R.color.secondary_text_light);\r
+ textView.setTextAppearance(context, R.style.Theme_Light_Token);\r
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 5 * fontSizeSp / 4);\r
return textView;\r
}\r