Code cleanup following IDE advice
app/src/main/java/eu/lepiller/nani/DictionaryActivity.java
7 | 7 | import androidx.appcompat.widget.Toolbar; | |
8 | 8 | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; | |
9 | 9 | ||
10 | + | import android.util.Log; | |
10 | 11 | import android.view.View; | |
11 | 12 | import android.widget.AdapterView; | |
12 | 13 | import android.widget.ListView; | |
… | |||
28 | 29 | ||
29 | 30 | public class DictionaryActivity extends AppCompatActivity { | |
30 | 31 | static final int DICO_REQUEST = 1; | |
32 | + | static final String TAG = "DLIST"; | |
31 | 33 | DictionariesAdapter adapter; | |
32 | 34 | ArrayList<Dictionary> dictionaries; | |
33 | 35 | ||
… | |||
85 | 87 | if(connection.getResponseCode() == HttpURLConnection.HTTP_OK) { | |
86 | 88 | InputStream input = connection.getInputStream(); | |
87 | 89 | File file = DictionaryFactory.getListFile(); | |
88 | - | file.getParentFile().mkdirs(); | |
89 | - | int count = 0; | |
90 | + | File parent = file.getParentFile(); | |
91 | + | if(parent != null && !parent.exists()) | |
92 | + | if(!parent.mkdirs()) | |
93 | + | Log.w(TAG, "Could not create parent directory for " + file); | |
94 | + | int count; | |
90 | 95 | byte[] data = new byte[4096]; | |
91 | 96 | FileOutputStream output = new FileOutputStream(file); | |
92 | 97 | while((count = input.read(data)) != -1) { |
app/src/main/java/eu/lepiller/nani/DictionaryDownloadActivity.java
1 | 1 | package eu.lepiller.nani; | |
2 | 2 | ||
3 | 3 | import android.app.NotificationManager; | |
4 | - | import android.content.Context; | |
5 | 4 | import android.graphics.drawable.Drawable; | |
6 | 5 | import android.os.AsyncTask; | |
7 | 6 | import android.os.Build; | |
… | |||
13 | 12 | import android.util.Log; | |
14 | 13 | import android.util.Pair; | |
15 | 14 | import android.view.View; | |
16 | - | import android.widget.ImageButton; | |
17 | 15 | import android.widget.ImageView; | |
18 | 16 | import android.widget.LinearLayout; | |
19 | 17 | import android.widget.ProgressBar; | |
… | |||
79 | 77 | protected void onCreate(Bundle savedInstanceState) { | |
80 | 78 | super.onCreate(savedInstanceState); | |
81 | 79 | setContentView(R.layout.activity_dictionary_download); | |
80 | + | Bundle extras = getIntent().getExtras(); | |
82 | 81 | ||
83 | - | int position = getIntent().getExtras().getInt("dico"); | |
82 | + | // TODO: this will open the first dictionary on error, we probably want to display a proper | |
83 | + | // error instead. | |
84 | + | int position = 0; | |
85 | + | if(extras != null) | |
86 | + | position = extras.getInt("dico"); | |
84 | 87 | ||
85 | 88 | d = DictionaryFactory.get(position); | |
86 | 89 | ||
… | |||
198 | 201 | if(connection.getResponseCode() == HttpURLConnection.HTTP_OK) { | |
199 | 202 | input = connection.getInputStream(); | |
200 | 203 | file = new File(cacheFile + ".sha256"); | |
201 | - | file.getParentFile().mkdirs(); | |
204 | + | if(file.getParentFile() == null || (!file.getParentFile().exists() && !file.getParentFile().mkdirs())) | |
205 | + | Log.w(TAG, "could not create parent of " + file); | |
202 | 206 | File old_file = new File(file + ".old"); | |
203 | 207 | if(old_file.exists()) { | |
204 | - | old_file.delete(); | |
208 | + | if(!old_file.delete()) | |
209 | + | Log.w(TAG, "could not delete file " + old_file); | |
205 | 210 | } | |
206 | 211 | if(file.exists()) { | |
207 | - | file.renameTo(old_file); | |
212 | + | if(!file.renameTo(old_file)) | |
213 | + | Log.w(TAG, "could not rename "+ file + " to " + old_file); | |
208 | 214 | } | |
209 | 215 | output = new FileOutputStream(file); | |
210 | 216 | while((count = input.read(data)) != -1) { | |
… | |||
225 | 231 | d.remove(); | |
226 | 232 | } | |
227 | 233 | ||
228 | - | old_file.delete(); | |
234 | + | if(!old_file.delete()) | |
235 | + | Log.w(TAG, "could not delete file " + old_file); | |
229 | 236 | } | |
230 | 237 | } | |
231 | 238 | ||
232 | 239 | // .sha256 file now downloaded | |
233 | 240 | url = new URL(uri); | |
234 | 241 | file = temporaryFile; | |
235 | - | file.getParentFile().mkdirs(); | |
242 | + | if(file.getParentFile() == null || (!file.getParentFile().exists() && !file.getParentFile().mkdirs())) | |
243 | + | Log.w(TAG, "could not create parent of " + file); | |
236 | 244 | long expectedLength = -1; | |
237 | 245 | boolean acceptRanges = false; | |
238 | 246 | if(file.exists()) { | |
… | |||
246 | 254 | acceptRanges = connection.getHeaderFields().containsKey("accept-ranges"); | |
247 | 255 | if (acceptRanges) { | |
248 | 256 | List<String> headers = connection.getHeaderFields().get("accept-ranges"); | |
249 | - | for(String h: headers) { | |
250 | - | if(h.toLowerCase().compareTo("none") == 0) | |
251 | - | acceptRanges = false; | |
257 | + | if(headers != null) { | |
258 | + | for (String h : headers) { | |
259 | + | if (h.toLowerCase().compareTo("none") == 0) | |
260 | + | acceptRanges = false; | |
261 | + | } | |
252 | 262 | } | |
253 | 263 | } | |
254 | 264 | Log.d(TAG, "Can do range? " + acceptRanges); |
app/src/main/java/eu/lepiller/nani/MainActivity.java
60 | 60 | "Nani's dictionary download notification", NotificationManager.IMPORTANCE_DEFAULT); | |
61 | 61 | NotificationManager manager = | |
62 | 62 | (NotificationManager) getSystemService(NOTIFICATION_SERVICE); | |
63 | - | manager.createNotificationChannel(channel); | |
63 | + | if(manager != null) | |
64 | + | manager.createNotificationChannel(channel); | |
64 | 65 | } | |
65 | 66 | ||
66 | 67 | PreferenceManager.setDefaultValues(this, R.xml.preferences, false); | |
… | |||
216 | 217 | }); | |
217 | 218 | } | |
218 | 219 | savedResults = searchResult; | |
219 | - | showResults(searchResult); | |
220 | + | if(searchResult != null) | |
221 | + | showResults(searchResult); | |
220 | 222 | } | |
221 | 223 | ||
222 | 224 | void showResults(ArrayList<Result> searchResult) { |
app/src/main/java/eu/lepiller/nani/RadicalSelectorView.java
1 | 1 | package eu.lepiller.nani; | |
2 | 2 | ||
3 | 3 | import android.content.Context; | |
4 | - | import android.content.SharedPreferences; | |
5 | 4 | import android.os.AsyncTask; | |
6 | 5 | import android.os.Build; | |
7 | 6 | import android.util.AttributeSet; | |
… | |||
17 | 16 | import com.google.android.flexbox.FlexWrap; | |
18 | 17 | import com.google.android.flexbox.FlexboxLayout; | |
19 | 18 | ||
19 | + | import java.text.NumberFormat; | |
20 | 20 | import java.util.ArrayList; | |
21 | + | import java.util.Arrays; | |
21 | 22 | import java.util.List; | |
22 | 23 | import java.util.Map; | |
23 | 24 | import java.util.Set; | |
… | |||
27 | 28 | ||
28 | 29 | public class RadicalSelectorView extends LinearLayout implements OnTaskCompleted<Map<Integer, List<String>>>, | |
29 | 30 | OnOtherTaskCompleted<Pair<Map<Integer, List<String>>, Set<String>>> { | |
31 | + | static private String TAG = "RSV"; | |
30 | 32 | private Button close_button; | |
31 | 33 | private LinearLayout kanji_row1, kanji_row2; | |
32 | 34 | private LinearLayout radical_table; | |
… | |||
46 | 48 | public RadicalSelectorView(Context context, AttributeSet attrs, int defStyle) { | |
47 | 49 | super(context, attrs, defStyle); | |
48 | 50 | LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
51 | + | if(inflater == null) { | |
52 | + | Log.e(TAG, "Inflater is null!"); | |
53 | + | return; | |
54 | + | } | |
49 | 55 | inflater.inflate(R.layout.content_radicals, this); | |
50 | 56 | this.setOrientation(VERTICAL); | |
51 | 57 | } | |
… | |||
70 | 76 | resizeRadicals(); | |
71 | 77 | } | |
72 | 78 | ||
73 | - | public float getRadFontSize() { | |
79 | + | public int getRadFontSize() { | |
74 | 80 | return radSize / 8; | |
75 | 81 | } | |
76 | 82 | ||
… | |||
81 | 87 | ||
82 | 88 | for (int stroke : radicals.keySet()) { | |
83 | 89 | TextView strokeView = new TextView(getContext()); | |
84 | - | strokeView.setText(Integer.toString(stroke)); | |
90 | + | NumberFormat nf = NumberFormat.getInstance(); | |
91 | + | strokeView.setText(nf.format(stroke)); | |
85 | 92 | radical_table.addView(strokeView); | |
86 | 93 | ||
87 | 94 | FlexboxLayout box = new FlexboxLayout(getContext()); | |
88 | 95 | radical_table.addView(box); | |
89 | 96 | ||
90 | 97 | List<String> lst = radicals.get(stroke); | |
98 | + | if(lst == null) | |
99 | + | continue; | |
100 | + | ||
91 | 101 | for (final String radical : lst) { | |
92 | 102 | ToggleButton radicalButton = new ToggleButton(getContext()); | |
93 | 103 | radicalButton.setTextOff(radical); | |
… | |||
169 | 179 | @Override | |
170 | 180 | protected Pair<Map<Integer, List<String>>, Set<String>> doInBackground(String... sInput) { | |
171 | 181 | try { | |
172 | - | List<String> radicals = new ArrayList<>(); | |
173 | - | for(String s: sInput) radicals.add(s); | |
182 | + | List<String> radicals = Arrays.asList(sInput); | |
174 | 183 | return new Pair<>(dict.match(radicals), dict.availableRadicals(radicals)); | |
175 | 184 | } catch (IncompatibleFormatException e) { | |
176 | 185 | e.printStackTrace(); | |
… | |||
203 | 212 | int total = 0; | |
204 | 213 | int number = 0; | |
205 | 214 | for (int stroke : kanji.keySet()) { | |
206 | - | total += kanji.get(stroke).size(); | |
215 | + | List<String> s = kanji.get(stroke); | |
216 | + | if(s != null) | |
217 | + | total += s.size(); | |
207 | 218 | } | |
208 | 219 | for (int stroke : kanji.keySet()) { | |
209 | 220 | TextView strokeView = new TextView(getContext()); | |
210 | - | strokeView.setText(Integer.toString(stroke)); | |
221 | + | NumberFormat nf = NumberFormat.getInstance(); | |
222 | + | strokeView.setText(nf.format(stroke)); | |
211 | 223 | strokeView.setLayoutParams(new LayoutParams(66, 66)); | |
212 | 224 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | |
213 | 225 | strokeView.setTextColor(getContext().getColor(R.color.colorAccent)); | |
… | |||
217 | 229 | } | |
218 | 230 | row.addView(strokeView); | |
219 | 231 | ||
220 | - | for (String k : kanji.get(stroke)) { | |
232 | + | List<String> kanjis = kanji.get(stroke); | |
233 | + | if(kanjis == null) | |
234 | + | continue; | |
235 | + | ||
236 | + | for (String k : kanjis) { | |
221 | 237 | number++; | |
222 | 238 | Button kanji_button = new Button(getContext()); | |
223 | 239 | kanji_button.setText(k); |
app/src/main/java/eu/lepiller/nani/SearchResult.java
5 | 5 | import eu.lepiller.nani.dictionary.DictionaryException; | |
6 | 6 | import eu.lepiller.nani.result.Result; | |
7 | 7 | ||
8 | - | public class SearchResult { | |
8 | + | class SearchResult { | |
9 | 9 | private ArrayList<Result> results; | |
10 | 10 | private DictionaryException exception; | |
11 | 11 | private boolean converted; |
app/src/main/java/eu/lepiller/nani/SettingsFragment.java
5 | 5 | import androidx.fragment.app.Fragment; | |
6 | 6 | import androidx.preference.PreferenceFragmentCompat; | |
7 | 7 | ||
8 | - | import android.view.LayoutInflater; | |
9 | - | import android.view.View; | |
10 | - | import android.view.ViewGroup; | |
11 | - | import android.widget.TextView; | |
12 | - | ||
13 | 8 | /** | |
14 | 9 | * A simple {@link Fragment} subclass. | |
15 | 10 | */ |
app/src/main/java/eu/lepiller/nani/dictionary/DictionariesAdapter.java
9 | 9 | import android.widget.ImageView; | |
10 | 10 | import android.widget.TextView; | |
11 | 11 | ||
12 | + | import androidx.annotation.NonNull; | |
13 | + | ||
12 | 14 | import java.text.NumberFormat; | |
13 | 15 | import java.util.ArrayList; | |
14 | 16 | ||
15 | 17 | import eu.lepiller.nani.R; | |
16 | 18 | ||
17 | 19 | public class DictionariesAdapter extends ArrayAdapter<Dictionary> { | |
18 | - | Context context; | |
20 | + | private Context context; | |
19 | 21 | public DictionariesAdapter(Context context, ArrayList<Dictionary> dictionaries) { | |
20 | 22 | super(context, 0, dictionaries); | |
21 | 23 | this.context = context; | |
22 | 24 | } | |
23 | 25 | ||
24 | - | @Override | |
25 | - | public View getView(int position, View convertView, ViewGroup parent) { | |
26 | + | @Override @NonNull | |
27 | + | public View getView(int position, View convertView, @NonNull ViewGroup parent) { | |
26 | 28 | // Get the data item for this position | |
27 | 29 | Dictionary dictionary = getItem(position); | |
28 | 30 | ||
… | |||
45 | 47 | // Populate the data into the template view using the data object | |
46 | 48 | Drawable icon = dictionary.getDrawable(context); | |
47 | 49 | if(icon != null) { | |
48 | - | icon = icon.getConstantState().newDrawable().mutate(); | |
49 | - | if(!dictionary.isDownloaded()) | |
50 | - | icon.setAlpha(64); | |
51 | - | else | |
52 | - | icon.setAlpha(255); | |
50 | + | Drawable.ConstantState state = icon.getConstantState(); | |
51 | + | if(state != null) { | |
52 | + | icon = state.newDrawable().mutate(); | |
53 | + | if (!dictionary.isDownloaded()) | |
54 | + | icon.setAlpha(64); | |
55 | + | else | |
56 | + | icon.setAlpha(255); | |
57 | + | } | |
53 | 58 | icon_view.setImageDrawable(icon); | |
54 | 59 | } | |
55 | 60 |
app/src/main/java/eu/lepiller/nani/dictionary/Dictionary.java
3 | 3 | import android.content.Context; | |
4 | 4 | import android.graphics.drawable.Drawable; | |
5 | 5 | import android.os.Build; | |
6 | - | import android.util.Log; | |
7 | 6 | import android.util.Pair; | |
8 | 7 | ||
9 | 8 | import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat; | |
… | |||
14 | 13 | import java.io.FileReader; | |
15 | 14 | import java.io.IOException; | |
16 | 15 | import java.math.BigInteger; | |
17 | - | import java.net.URL; | |
18 | 16 | import java.security.MessageDigest; | |
19 | 17 | import java.security.NoSuchAlgorithmException; | |
20 | 18 | import java.util.Map; | |
… | |||
25 | 23 | private int expectedFileSize; | |
26 | 24 | private int expectedEntries; | |
27 | 25 | private String sha256; | |
28 | - | File file, temporaryFile; | |
26 | + | private File file, temporaryFile; | |
29 | 27 | ||
30 | 28 | Dictionary(String n, String descr, String fullDescr, File cacheDir, int fileSize, int entries, String hash) { | |
31 | 29 | name = n; | |
… | |||
50 | 48 | public int getExpectedFileSize() { | |
51 | 49 | return expectedFileSize; | |
52 | 50 | } | |
53 | - | public int getExpectedEntries() { | |
51 | + | int getExpectedEntries() { | |
54 | 52 | return expectedEntries; | |
55 | 53 | } | |
56 | - | public String getSha256() { | |
54 | + | String getSha256() { | |
57 | 55 | return sha256; | |
58 | 56 | } | |
59 | 57 | abstract public boolean isUpToDate(); | |
… | |||
72 | 70 | ||
73 | 71 | abstract public int size(); | |
74 | 72 | ||
75 | - | // Used for downloads: tells what size we currently have downloaded | |
76 | - | abstract int currentSize(); | |
77 | - | ||
78 | 73 | public abstract Map<String, Pair<File, File>> getDownloads(); | |
79 | 74 | ||
80 | 75 | public Drawable getDrawable(Context context) { | |
… | |||
94 | 89 | ||
95 | 90 | public static String readSha256FromFile(File file) throws IOException { | |
96 | 91 | StringBuilder sb = new StringBuilder(); | |
97 | - | char data[] = new char[4096]; | |
92 | + | char[] data = new char[4096]; | |
98 | 93 | FileReader fr = new FileReader(file); | |
99 | 94 | int count; | |
100 | 95 | while((count = fr.read(data)) != -1) { | |
… | |||
104 | 99 | return sb.toString().trim(); | |
105 | 100 | } | |
106 | 101 | ||
107 | - | public static String sha256OfFile(File file) { | |
102 | + | static String sha256OfFile(File file) { | |
108 | 103 | MessageDigest digest=null; | |
109 | 104 | try { | |
110 | 105 | digest = MessageDigest.getInstance("SHA-256"); | |
111 | 106 | } catch (NoSuchAlgorithmException e) { | |
112 | 107 | e.printStackTrace(); | |
113 | 108 | } | |
109 | + | if(digest == null) | |
110 | + | return null; | |
111 | + | ||
114 | 112 | digest.reset(); | |
115 | 113 | try { | |
116 | - | byte data[] = new byte[4096]; | |
114 | + | byte[] data = new byte[4096]; | |
117 | 115 | FileInputStream fr = new FileInputStream(file); | |
118 | 116 | int count; | |
119 | 117 | while((count = fr.read(data)) != -1) { |
app/src/main/java/eu/lepiller/nani/dictionary/DictionaryFactory.java
3 | 3 | import android.content.Context; | |
4 | 4 | import android.os.Build; | |
5 | 5 | import android.os.LocaleList; | |
6 | - | import android.util.ArrayMap; | |
7 | 6 | import android.util.Log; | |
8 | 7 | ||
9 | 8 | import java.io.BufferedReader; | |
10 | 9 | import java.io.File; | |
11 | - | import java.io.FileInputStream; | |
12 | 10 | import java.io.FileNotFoundException; | |
13 | 11 | import java.io.FileReader; | |
14 | 12 | import java.io.IOException; | |
… | |||
20 | 18 | import java.util.Locale; | |
21 | 19 | import java.util.Map; | |
22 | 20 | ||
23 | - | import eu.lepiller.nani.R; | |
24 | 21 | import eu.lepiller.nani.result.Result; | |
25 | 22 | ||
26 | 23 | public class DictionaryFactory { | |
… | |||
60 | 57 | ||
61 | 58 | private static String chooseLanguage(Map<String, StringBuilder> data) { | |
62 | 59 | for(String l: languages) { | |
63 | - | if(data.containsKey(l)) | |
64 | - | return data.get(l).toString(); | |
60 | + | if(data.containsKey(l)) { | |
61 | + | StringBuilder sb = data.get(l); | |
62 | + | if(sb != null) | |
63 | + | return sb.toString(); | |
64 | + | } | |
65 | 65 | } | |
66 | 66 | return null; | |
67 | 67 | } |
app/src/main/java/eu/lepiller/nani/dictionary/FileDictionary.java
12 | 12 | import java.util.Map; | |
13 | 13 | ||
14 | 14 | public abstract class FileDictionary extends Dictionary { | |
15 | + | String encoding = "UTF-8"; | |
16 | + | ||
15 | 17 | interface Huffman { | |
16 | 18 | } | |
17 | 19 | ||
… | |||
47 | 49 | public void switchToCacheFile() { | |
48 | 50 | if(checkTemporaryFile()) { | |
49 | 51 | if(getFile().exists()) { | |
50 | - | getFile().delete(); | |
52 | + | if(!getFile().delete()) | |
53 | + | Log.w(TAG, getFile() + " was not deleted as expected."); | |
51 | 54 | } | |
52 | - | getTemporaryFile().renameTo(getFile()); | |
55 | + | ||
56 | + | if(!getTemporaryFile().renameTo(getFile())) | |
57 | + | Log.w(TAG, getTemporaryFile() + " was not renamed to " + getFile() + " as expected."); | |
53 | 58 | } | |
54 | 59 | } | |
55 | 60 | ||
… | |||
59 | 64 | File sha256 = new File(getFile() + ".sha256"); | |
60 | 65 | if(sha256.exists()) { | |
61 | 66 | String hash = sha256OfFile(f); | |
67 | + | if(hash == null) | |
68 | + | return false; | |
62 | 69 | ||
63 | 70 | try { | |
64 | 71 | String expected = readSha256FromFile(sha256); | |
… | |||
102 | 109 | } | |
103 | 110 | ||
104 | 111 | @Override | |
105 | - | int currentSize() { | |
106 | - | return 0; | |
107 | - | } | |
108 | - | ||
109 | - | @Override | |
110 | 112 | public Map<String, Pair<File, File>> getDownloads() { | |
111 | 113 | HashMap<String, Pair<File, File>> result = new HashMap<>(); | |
112 | 114 | Pair<File, File> pair = new Pair<>(getTemporaryFile(), getFile()); | |
… | |||
117 | 119 | @Override | |
118 | 120 | public void remove() { | |
119 | 121 | if(getFile().exists()) | |
120 | - | getFile().delete(); | |
122 | + | if(!getFile().delete()) | |
123 | + | Log.w(TAG, getFile() + " was not deleted as expected."); | |
121 | 124 | if(getTemporaryFile().exists()) | |
122 | - | getTemporaryFile().delete(); | |
125 | + | if(!getTemporaryFile().delete()) | |
126 | + | Log.w(TAG, getTemporaryFile() + " was not deleted as expected."); | |
123 | 127 | } | |
124 | 128 | ||
125 | 129 | ||
… | |||
142 | 146 | for(int j=0; j<bs.size(); j++) { | |
143 | 147 | str[j] = bs.get(j); | |
144 | 148 | } | |
145 | - | return new String(str, "UTF-8"); | |
149 | + | return new String(str, encoding); | |
146 | 150 | } | |
147 | 151 | ||
148 | 152 | ArrayList<String> getStringList(RandomAccessFile file) throws IOException { | |
… | |||
158 | 162 | ArrayList<Integer> results = new ArrayList<>(); | |
159 | 163 | int number = file.readShort(); | |
160 | 164 | for(int i=0; i<number; i++) { | |
161 | - | results.add(Integer.valueOf(file.readByte())); | |
165 | + | results.add((int) file.readByte()); | |
162 | 166 | } | |
163 | 167 | return results; | |
164 | 168 | } | |
… | |||
183 | 187 | for(int i=0; i<bs.size(); i++) { | |
184 | 188 | array[i] = bs.get(i); | |
185 | 189 | } | |
186 | - | return new HuffmanValue(new String(array, "UTF-8")); | |
190 | + | return new HuffmanValue(new String(array, encoding)); | |
187 | 191 | } | |
188 | 192 | } | |
189 | 193 | ||
190 | - | String getHuffmanString(RandomAccessFile file, Huffman huffman) throws IOException { | |
194 | + | private String getHuffmanString(RandomAccessFile file, Huffman huffman) throws IOException { | |
191 | 195 | StringBuilder b = new StringBuilder(); | |
192 | 196 | ArrayList<Boolean> bits = new ArrayList<>(); | |
193 | 197 | String c = null; |
app/src/main/java/eu/lepiller/nani/dictionary/IncompatibleFormatException.java
1 | 1 | package eu.lepiller.nani.dictionary; | |
2 | 2 | ||
3 | 3 | public class IncompatibleFormatException extends DictionaryException { | |
4 | - | String name; | |
4 | + | private String name; | |
5 | 5 | ||
6 | - | public IncompatibleFormatException(String name) { | |
6 | + | IncompatibleFormatException(String name) { | |
7 | 7 | this.name = name; | |
8 | 8 | } | |
9 | 9 |
app/src/main/java/eu/lepiller/nani/dictionary/JMDict.java
6 | 6 | import java.io.FileNotFoundException; | |
7 | 7 | import java.io.IOException; | |
8 | 8 | import java.io.RandomAccessFile; | |
9 | - | import java.net.MalformedURLException; | |
10 | - | import java.net.URL; | |
11 | 9 | import java.util.ArrayList; | |
12 | 10 | import java.util.Arrays; | |
13 | - | import java.util.HashMap; | |
14 | - | import java.util.Map; | |
15 | 11 | ||
16 | 12 | import eu.lepiller.nani.R; | |
17 | 13 | import eu.lepiller.nani.result.Result; | |
… | |||
111 | 107 | ||
112 | 108 | private ArrayList<Integer> searchTrie(RandomAccessFile file, long triePos, byte[] txt) throws IOException { | |
113 | 109 | Log.d(TAG, "searchTrie: " + triePos); | |
114 | - | Log.d(TAG, "Remaining transitions: " + new String(txt, "UTF-8")); | |
110 | + | Log.d(TAG, "Remaining transitions: " + new String(txt, encoding)); | |
115 | 111 | file.seek(triePos); | |
116 | 112 | Log.d(TAG, "pointer: " + file.getFilePointer()); | |
117 | 113 | if(txt.length == 0) { |