Fix warnings from the IDE
.idea/dictionaries/tyreunom.xml
| 2 | 2 | <dictionary name="tyreunom"> | |
| 3 | 3 | <words> | |
| 4 | 4 | <w>dico</w> | |
| 5 | + | <w>jmdict</w> | |
| 5 | 6 | <w>kanji</w> | |
| 6 | 7 | <w>kanjis</w> | |
| 7 | 8 | <w>lepiller</w> | |
| 9 | + | <w>moji</w> | |
| 8 | 10 | <w>mozc</w> | |
| 11 | + | <w>radk</w> | |
| 12 | + | <w>romaji</w> | |
| 13 | + | <w>wasei</w> | |
| 9 | 14 | </words> | |
| 10 | 15 | </dictionary> | |
| 11 | 16 | </component> | |
| 11 | 16 | = | |
| 12 | 17 | = | \ No newline at end of file |
app/src/main/java/eu/lepiller/nani/AboutActivity.java
| 40 | 40 | String appPackageName = "org.mozc.android.inputmethod.japanese"; | |
| 41 | 41 | try { | |
| 42 | 42 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); | |
| 43 | - | } catch (android.content.ActivityNotFoundException anfe) { | |
| 43 | + | } catch (android.content.ActivityNotFoundException e) { | |
| 44 | 44 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName))); | |
| 45 | 45 | } | |
| 46 | 46 | } |
app/src/main/java/eu/lepiller/nani/DictionaryActivity.java
| 44 | 44 | final ListView list_view = findViewById(R.id.dictionary_view); | |
| 45 | 45 | refresher = findViewById(R.id.dictionary_refresh_layout); | |
| 46 | 46 | ||
| 47 | - | dictionaries = DictionaryFactory.getDictionnaries(getApplicationContext()); | |
| 47 | + | dictionaries = DictionaryFactory.getDictionaries(getApplicationContext()); | |
| 48 | 48 | adapter = new DictionariesAdapter(this, dictionaries); | |
| 49 | 49 | list_view.setAdapter(adapter); | |
| 50 | 50 | ||
… | |||
| 156 | 156 | private void updateDataSet() { | |
| 157 | 157 | DictionaryFactory.updatePackageList(); | |
| 158 | 158 | dictionaries.clear(); | |
| 159 | - | dictionaries.addAll(DictionaryFactory.getDictionnaries(getApplicationContext())); | |
| 159 | + | dictionaries.addAll(DictionaryFactory.getDictionaries(getApplicationContext())); | |
| 160 | 160 | adapter.notifyDataSetChanged(); | |
| 161 | 161 | } | |
| 162 | 162 | ||
app/src/main/java/eu/lepiller/nani/MainActivity.java
| 1 | 1 | package eu.lepiller.nani; | |
| 2 | 2 | ||
| 3 | - | import android.app.NotificationChannel; | |
| 4 | - | import android.app.NotificationManager; | |
| 5 | 3 | import android.content.Intent; | |
| 6 | 4 | import android.content.SharedPreferences; | |
| 7 | 5 | import android.os.AsyncTask; | |
… | |||
| 60 | 58 | SharedPreferences sharedPref = | |
| 61 | 59 | PreferenceManager.getDefaultSharedPreferences(this); | |
| 62 | 60 | sharedPref.registerOnSharedPreferenceChangeListener(this); | |
| 63 | - | int radSizePref = Integer.parseInt(sharedPref.getString | |
| 64 | - | (SettingsActivity.KEY_PREF_RAD_SIZE, "122")); | |
| 61 | + | int radSizePref = getRadSizePref(sharedPref); | |
| 65 | 62 | ||
| 66 | 63 | try { | |
| 67 | 64 | radical_selector.setRadSize(radSizePref); | |
… | |||
| 136 | 133 | @Override | |
| 137 | 134 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { | |
| 138 | 135 | if(key.compareTo(SettingsActivity.KEY_PREF_RAD_SIZE) == 0) { | |
| 139 | - | int radSizePref = Integer.parseInt(sharedPreferences.getString | |
| 140 | - | (SettingsActivity.KEY_PREF_RAD_SIZE, "122")); | |
| 141 | - | radical_selector.setRadSize(radSizePref); | |
| 136 | + | radical_selector.setRadSize(getRadSizePref(sharedPreferences)); | |
| 142 | 137 | } | |
| 143 | 138 | } | |
| 144 | 139 | ||
| 140 | + | private int getRadSizePref(SharedPreferences sharedPrefs) { | |
| 141 | + | String prefRadSize = sharedPrefs.getString(SettingsActivity.KEY_PREF_RAD_SIZE, "122"); | |
| 142 | + | if(prefRadSize == null) | |
| 143 | + | prefRadSize = "122"; | |
| 144 | + | return Integer.parseInt(prefRadSize); | |
| 145 | + | } | |
| 146 | + | ||
| 145 | 147 | private static class SearchTask extends AsyncTask<String, Integer, SearchResult> { | |
| 146 | 148 | OnTaskCompleted<SearchResult> callback; | |
| 147 | 149 | SearchTask(OnTaskCompleted<SearchResult> callback) { | |
app/src/main/java/eu/lepiller/nani/dictionary/DictionariesAdapter.java
| 48 | 48 | ||
| 49 | 49 | // Populate the data into the template view using the data object | |
| 50 | 50 | Drawable icon; | |
| 51 | - | if (dictionary.isDownloaded() && !dictionary.isUpToDate()) | |
| 51 | + | if (dictionary.isDownloaded() && dictionary.canUpdate()) | |
| 52 | 52 | icon = dictionary.getNewDrawable(context); | |
| 53 | 53 | else | |
| 54 | 54 | icon = dictionary.getDrawable(context); | |
… | |||
| 66 | 66 | } | |
| 67 | 67 | ||
| 68 | 68 | name_view.setText(dictionary.getName()); | |
| 69 | - | if(!dictionary.isUpToDate() && dictionary.isDownloaded()) { | |
| 69 | + | if(dictionary.canUpdate() && dictionary.isDownloaded()) { | |
| 70 | 70 | name_view.setTypeface(null, Typeface.BOLD); | |
| 71 | 71 | } else { | |
| 72 | 72 | name_view.setTypeface(null, Typeface.NORMAL); | |
app/src/main/java/eu/lepiller/nani/dictionary/Dictionary.java
| 2 | 2 | ||
| 3 | 3 | import android.content.Context; | |
| 4 | 4 | import android.graphics.Bitmap; | |
| 5 | - | import android.graphics.BitmapFactory; | |
| 6 | 5 | import android.graphics.Canvas; | |
| 7 | 6 | import android.graphics.drawable.BitmapDrawable; | |
| 8 | 7 | import android.graphics.drawable.Drawable; | |
| 9 | 8 | import android.os.Build; | |
| 10 | - | import android.util.Log; | |
| 11 | 9 | import android.util.Pair; | |
| 12 | 10 | ||
| 13 | 11 | import java.io.File; | |
… | |||
| 32 | 30 | ||
| 33 | 31 | private static Drawable drawable=null, newDrawable=null; | |
| 34 | 32 | ||
| 35 | - | Dictionary(String n, String descr, String fullDescr, File cacheDir, int fileSize, int entries, String hash) { | |
| 36 | - | name = n; | |
| 37 | - | description = descr; | |
| 38 | - | fullDescription = fullDescr; | |
| 33 | + | Dictionary(String name, String description, String fullDescription, File cacheDir, int fileSize, int entries, String hash) { | |
| 34 | + | this.name = name; | |
| 35 | + | this.description = description; | |
| 36 | + | this.fullDescription = fullDescription; | |
| 39 | 37 | expectedEntries = entries; | |
| 40 | 38 | expectedFileSize = fileSize; | |
| 41 | 39 | sha256 = hash; | |
… | |||
| 61 | 59 | String getSha256() { | |
| 62 | 60 | return sha256; | |
| 63 | 61 | } | |
| 64 | - | abstract public boolean isUpToDate(); | |
| 62 | + | abstract public boolean canUpdate(); | |
| 65 | 63 | ||
| 66 | 64 | File getFile() { | |
| 67 | 65 | return file; | |
app/src/main/java/eu/lepiller/nani/dictionary/DictionaryFactory.java
| 14 | 14 | import java.net.URL; | |
| 15 | 15 | import java.util.ArrayList; | |
| 16 | 16 | import java.util.HashMap; | |
| 17 | - | import java.util.HashSet; | |
| 18 | 17 | import java.util.List; | |
| 19 | 18 | import java.util.Locale; | |
| 20 | 19 | import java.util.Map; | |
… | |||
| 227 | 226 | return dictionaries.get(position); | |
| 228 | 227 | } | |
| 229 | 228 | ||
| 230 | - | public static ArrayList<Dictionary> getDictionnaries(Context context) { | |
| 229 | + | public static ArrayList<Dictionary> getDictionaries(Context context) { | |
| 231 | 230 | if(instance == null) | |
| 232 | 231 | instance = new DictionaryFactory(context); | |
| 233 | 232 | ||
app/src/main/java/eu/lepiller/nani/dictionary/FileDictionary.java
| 32 | 32 | } | |
| 33 | 33 | ||
| 34 | 34 | private String mUrl; | |
| 35 | - | private static String TAG = "FILEDIC"; | |
| 35 | + | private final static String TAG = "FileDictionary"; | |
| 36 | 36 | ||
| 37 | 37 | FileDictionary(String name, String description, String fullDescription, File cacheDir, String url, | |
| 38 | 38 | int fileSize, int entries, String hash) { | |
… | |||
| 87 | 87 | return false; | |
| 88 | 88 | } | |
| 89 | 89 | ||
| 90 | - | public boolean isUpToDate() { | |
| 90 | + | public boolean canUpdate() { | |
| 91 | 91 | File sha256 = new File(getFile() + ".sha256"); | |
| 92 | 92 | if(!sha256.exists()) | |
| 93 | - | return true; | |
| 93 | + | return false; | |
| 94 | 94 | ||
| 95 | 95 | try { | |
| 96 | 96 | String current = readSha256FromFile(sha256); | |
| 97 | 97 | String latest = getSha256(); | |
| 98 | 98 | ||
| 99 | - | return latest.compareTo(current) == 0; | |
| 99 | + | return latest.compareTo(current) != 0; | |
| 100 | 100 | } catch (IOException e) { | |
| 101 | 101 | e.printStackTrace(); | |
| 102 | - | return true; | |
| 102 | + | return false; | |
| 103 | 103 | } | |
| 104 | 104 | } | |
| 105 | 105 | ||
… | |||
| 221 | 221 | return b.toString(); | |
| 222 | 222 | } | |
| 223 | 223 | ||
| 224 | - | static void logHuffman(Huffman h, ArrayList<Boolean> addr) { | |
| 224 | + | static void logHuffman(Huffman h, ArrayList<Boolean> address) { | |
| 225 | 225 | if (h instanceof JMDict.HuffmanValue) { | |
| 226 | - | Log.d(TAG, "HUFF: " + ((JMDict.HuffmanValue) h).character + " -> " + addr.toString()); | |
| 226 | + | Log.d(TAG, "HUFF: " + ((JMDict.HuffmanValue) h).character + " -> " + address.toString()); | |
| 227 | 227 | } else if(h instanceof JMDict.HuffmanTree) { | |
| 228 | - | ArrayList<Boolean> addr_l = new ArrayList<>(addr); | |
| 229 | - | addr_l.add(false); | |
| 230 | - | ArrayList<Boolean> addr_r = new ArrayList<>(addr); | |
| 231 | - | addr_r.add(true); | |
| 232 | - | logHuffman(((JMDict.HuffmanTree) h).left, addr_l); | |
| 233 | - | logHuffman(((JMDict.HuffmanTree) h).right, addr_r); | |
| 228 | + | ArrayList<Boolean> address_l = new ArrayList<>(address); | |
| 229 | + | address_l.add(false); | |
| 230 | + | ArrayList<Boolean> address_r = new ArrayList<>(address); | |
| 231 | + | address_r.add(true); | |
| 232 | + | logHuffman(((JMDict.HuffmanTree) h).left, address_l); | |
| 233 | + | logHuffman(((JMDict.HuffmanTree) h).right, address_r); | |
| 234 | 234 | } | |
| 235 | 235 | } | |
| 236 | 236 | ||