import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.net.Uri;
+import android.os.Build;
import android.os.Environment;
import android.preference.PreferenceManager;
+import android.support.v4.view.MenuItemCompat;
import android.util.Log;
import android.util.TypedValue;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView.ScaleType;
+import android.widget.LinearLayout;
+import android.widget.Toast;
-import android.support.v4.view.MenuItemCompat;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MenuItem.OnMenuItemClickListener;
import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;
import com.hughes.android.dictionary.engine.Dictionary;
import com.hughes.android.dictionary.engine.Language;
static final String LOG = "QuickDicApp";
+ // If set to false, avoid use of ICU collator
+ // Works well enough for most european languages,
+ // gives faster startup and avoids crashes on some
+ // devices due to Dalvik bugs (e.g. ARMv6, S5570i, CM11).
+ // Leave it enabled by default for correctness except
+ // for my known broken development/performance test device config.
+ static public final boolean USE_COLLATOR = !android.os.Build.FINGERPRINT.equals("Samsung/cm_tassve/tassve:4.4.4/KTU84Q/20150211:userdebug/release-keys");
+
// Static, determined by resources (and locale).
// Unordered.
static Map<String, DictionaryInfo> DOWNLOADABLE_UNCOMPRESSED_FILENAME_NAME_TO_DICTIONARY_INFO = null;
+ enum Theme {
+ DEFAULT(R.style.Theme_Default,
+ R.style.Theme_Default_TokenRow_Fg,
+ R.color.theme_default_token_row_fg,
+ R.drawable.theme_default_token_row_main_bg,
+ R.drawable.theme_default_token_row_other_bg,
+ R.drawable.theme_default_normal_row_bg),
+
+ LIGHT(R.style.Theme_Light,
+ R.style.Theme_Light_TokenRow_Fg,
+ R.color.theme_light_token_row_fg,
+ R.drawable.theme_light_token_row_main_bg,
+ R.drawable.theme_light_token_row_other_bg,
+ R.drawable.theme_light_normal_row_bg);
+
+ Theme(final int themeId, final int tokenRowFg,
+ final int tokenRowFgColor,
+ final int tokenRowMainBg, final int tokenRowOtherBg,
+ final int normalRowBg) {
+ this.themeId = themeId;
+ this.tokenRowFg = tokenRowFg;
+ this.tokenRowFgColor = tokenRowFgColor;
+ this.tokenRowMainBg = tokenRowMainBg;
+ this.tokenRowOtherBg = tokenRowOtherBg;
+ this.normalRowBg = normalRowBg;
+ }
+
+ final int themeId;
+ final int tokenRowFg;
+ final int tokenRowFgColor;
+ final int tokenRowMainBg;
+ final int tokenRowOtherBg;
+ final int normalRowBg;
+ }
+
// Useful:
// http://www.loc.gov/standards/iso639-2/php/code_list.php
public static final Map<String, LanguageResources> isoCodeToResources = new LinkedHashMap<String, LanguageResources>();
MenuItemCompat.setShowAsAction(about, MenuItem.SHOW_AS_ACTION_NEVER);
about.setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(final MenuItem menuItem) {
- final Intent intent = new Intent().setClassName(AboutActivity.class
- .getPackage().getName(), AboutActivity.class.getCanonicalName());
+ final Intent intent = new Intent(getApplicationContext(), AboutActivity.class);
context.startActivity(intent);
return false;
}
MenuItemCompat.setShowAsAction(help, MenuItem.SHOW_AS_ACTION_NEVER);
help.setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(final MenuItem menuItem) {
- context.startActivity(HtmlDisplayActivity.getHelpLaunchIntent());
+ context.startActivity(HtmlDisplayActivity.getHelpLaunchIntent(getApplicationContext()));
return false;
}
});
preferences.setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(final MenuItem menuItem) {
PreferenceActivity.prefsMightHaveChanged = true;
- final Intent intent = new Intent().setClassName(PreferenceActivity.class
- .getPackage().getName(), PreferenceActivity.class.getCanonicalName());
+ final Intent intent = new Intent(getApplicationContext(), PreferenceActivity.class);
context.startActivity(intent);
return false;
}
public boolean onMenuItemClick(final MenuItem menuItem) {
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri
- .parse("http://code.google.com/p/quickdic-dictionary/issues/entry"));
+ .parse("http://github.com/rdoeffinger/Dictionary/issues"));
context.startActivity(intent);
return false;
}
}
dictDir = new File(dir);
dictDir.mkdirs();
+ if (!dictDir.isDirectory() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ getApplicationContext().getExternalFilesDirs(null);
+ }
return dictDir;
}
+ static public boolean checkFileCreate(File dir) {
+ boolean res = false;
+ File testfile = new File(dir, "quickdic_writetest");
+ try {
+ testfile.delete();
+ res = testfile.createNewFile() & testfile.delete();
+ } catch (Exception e) {
+ }
+ return res;
+ }
+
public File getWordListFile() {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String file = prefs.getString(getString(R.string.wordListFileKey), "");
return new File(file);
}
- public C.Theme getSelectedTheme() {
+ public Theme getSelectedTheme() {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
final String theme = prefs.getString(getString(R.string.themeKey), "themeLight");
if (theme.equals("themeLight")) {
- return C.Theme.LIGHT;
+ return Theme.LIGHT;
} else {
- return C.Theme.DEFAULT;
+ return Theme.DEFAULT;
}
}
button.setScaleType(ScaleType.FIT_CENTER);
result = button;
}
- result.setMinimumWidth(languageButtonPixels);
- result.setMinimumHeight(languageButtonPixels * 2 / 3);
- // result.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
- // LayoutParams.WRAP_CONTENT));
+ result.setLayoutParams(new LinearLayout.LayoutParams(languageButtonPixels, LinearLayout.LayoutParams.MATCH_PARENT));
return result;
}
public synchronized void deleteDictionary(final DictionaryInfo dictionaryInfo) {
while (dictionaryConfig.dictionaryFilesOrdered.remove(dictionaryInfo.uncompressedFilename)) {
}
- ;
dictionaryConfig.uncompressedFilenameToDictionaryInfo
.remove(dictionaryInfo.uncompressedFilename);
getPath(dictionaryInfo.uncompressedFilename).delete();
PersistentObjectCache.getInstance().write(C.DICTIONARY_CONFIGS, dictionaryConfig);
}
- final Collator collator = Collator.getInstance();
+ final Comparator collator = USE_COLLATOR ? Collator.getInstance() : String.CASE_INSENSITIVE_ORDER;
final Comparator<String> uncompressedFilenameComparator = new Comparator<String>() {
@Override
public int compare(String uncompressedFilename1, String uncompressedFilename2) {
file.getName(), dictionaryInfo);
}
} else {
- Log.w(LOG, "dictDir is not a diretory: " + getDictDir().getPath());
+ Log.w(LOG, "dictDir is not a directory: " + getDictDir().getPath());
}
if (!toAddSorted.isEmpty()) {
Collections.sort(toAddSorted, uncompressedFilenameComparator);