Add snackbars
app/src/main/java/eu/lepiller/nani/MainActivity.java
2 | 2 | ||
3 | 3 | import android.content.Intent; | |
4 | 4 | import android.os.Bundle; | |
5 | + | import android.support.design.widget.Snackbar; | |
5 | 6 | import android.support.v7.app.AppCompatActivity; | |
6 | 7 | import android.support.v7.widget.Toolbar; | |
7 | 8 | import android.view.View; | |
… | |||
14 | 15 | ||
15 | 16 | import java.util.ArrayList; | |
16 | 17 | ||
18 | + | import eu.lepiller.nani.dictionary.DictionaryException; | |
17 | 19 | import eu.lepiller.nani.dictionary.DictionaryFactory; | |
20 | + | import eu.lepiller.nani.dictionary.IncompatibleFormatException; | |
21 | + | import eu.lepiller.nani.dictionary.NoDictionaryException; | |
18 | 22 | import eu.lepiller.nani.result.Result; | |
19 | 23 | import se.fekete.furiganatextview.furiganaview.FuriganaTextView; | |
20 | 24 | ||
… | |||
35 | 39 | @Override | |
36 | 40 | public void onClick(View v) { | |
37 | 41 | String text = search_form.getText().toString(); | |
38 | - | ArrayList<Result> searchResult = DictionaryFactory.search(getApplicationContext(), text); | |
42 | + | if(text.isEmpty()) { | |
43 | + | Snackbar.make(findViewById(R.id.search_form), getString(R.string.no_search), Snackbar.LENGTH_LONG).show(); | |
44 | + | return; | |
45 | + | } | |
46 | + | ||
47 | + | ArrayList<Result> searchResult = null; | |
48 | + | try { | |
49 | + | searchResult = DictionaryFactory.search(getApplicationContext(), text); | |
50 | + | } catch (NoDictionaryException e) { | |
51 | + | Snackbar.make(findViewById(R.id.search_form), getString(R.string.no_dic), | |
52 | + | Snackbar.LENGTH_LONG).show(); | |
53 | + | return; | |
54 | + | } catch (IncompatibleFormatException e) { | |
55 | + | Snackbar.make(findViewById(R.id.search_form), String.format(getString(R.string.incompatible_format), e.getName()), | |
56 | + | Snackbar.LENGTH_LONG).show(); | |
57 | + | return; | |
58 | + | } catch (DictionaryException ignored) { | |
59 | + | return; | |
60 | + | } | |
39 | 61 | ||
40 | 62 | result_view.removeAllViews(); | |
41 | 63 | int num = 0; |
app/src/main/res/values/strings.xml
7 | 7 | <string name="search_hint">Search japanese word, kanji, meaning, ???</string> | |
8 | 8 | <string name="search_button">Search</string> | |
9 | 9 | <string name="title_activity_dictionary">Dictionaries</string> | |
10 | + | <string name="no_search">No search term</string> | |
11 | + | <string name="no_dic">You haven\'t downloaded any dictionary usable with this search function. Please select a dictionary.</string> | |
12 | + | <string name="incompatible_format">Dictionary %s is not compatible with this version of the application. Either update the dictionary or the app.</string> | |
10 | 13 | ||
11 | 14 | <string name="download">Download</string> | |
12 | 15 | <string name="remove">Remove</string> | |
13 | 16 | <string name="icon_description">Icon</string> | |
14 | 17 | <string name="kanji_description">Writing</string> | |
15 | 18 | ||
19 | + | <string name="dictionary_size">Actual size: %d MB</string> | |
20 | + | ||
16 | 21 | <!-- Dictionnary descriptions --> | |
17 | - | <string name="dico_jmdict_e">Japanese/English dictionary from the Electronic Dictionary Research and Development Group.\n~80 MB, ~180,000 entries.</string> | |
22 | + | <string name="dico_jmdict_e">Japanese/English dictionary from the Electronic Dictionary Research and Development Group.\n~56 MB, ~180,000 entries.</string> | |
18 | 23 | <string name="dico_jmdict_dut">Japanese/Dutch dictionary from the Electronic Dictionary Research and Development Group.\n~30 MB, ~35,000 entries.</string> | |
19 | - | <string name="dico_jmdict_fre">Japanese/French dictionary from the Electronic Dictionary Research and Development Group.\n~8 MB, ~15,000 entries.</string> | |
24 | + | <string name="dico_jmdict_fre">Japanese/French dictionary from the Electronic Dictionary Research and Development Group.\n~4 MB, ~15,000 entries.</string> | |
20 | 25 | <string name="dico_jmdict_ger">Japanese/German dictionary from the Electronic Dictionary Research and Development Group.\n~70 MB, ~120,000 entries.</string> | |
21 | 26 | <string name="dico_jmdict_hun">Japanese/Hungarian dictionary from the Electronic Dictionary Research and Development Group.\n~15 MB, ~40,000 entries.</string> | |
22 | 27 | <string name="dico_jmdict_rus">Japanese/Russian dictionary from the Electronic Dictionary Research and Development Group.\n~80 MB, ~65,000 entries.</string> | |
23 | 28 | <string name="dico_jmdict_slv">Japanese/Slovenian dictionary from the Electronic Dictionary Research and Development Group.\n~4 MB, ~9,000 entries.</string> | |
24 | 29 | <string name="dico_jmdict_spa">Japanese/Spanish dictionary from the Electronic Dictionary Research and Development Group.\n~15 MB, ~35,000 entries.</string> | |
25 | 30 | <string name="dico_jmdict_swe">Japanese/Swedish dictionary from the Electronic Dictionary Research and Development Group.\n~4 MB, ~15,000 entries.</string> | |
31 | + | <string name="dico_jmdict_long">This dictionary allows you to do searches on the main view of this app. | |
32 | + | Failing to download one of these dictionaries will make the app unusable as you can\'t search for anything. This dictionary can be searched for by | |
33 | + | kanji, reading (kana) and by meaning in the languages you selected.</string> | |
26 | 34 | ||
27 | 35 | <!-- Result view --> | |
28 | 36 | <string name="sense_number">%d.</string> | |
29 | 37 | <string name="sense_separator">"; "</string> | |
30 | 38 | <string name="sense_alternatives">Alternative forms: %s</string> | |
31 | 39 | ||
32 | - | <!-- JMdict tags, obtained with | |
33 | - | cat entities | cut -c 10- | sed -e 's|">$||' -e 's|.* "|<item>|' -e 's|$|</item>|' -e "s|\`|'|g" | sed "s|'|\\\'|g" | |
34 | - | --> | |
35 | - | <string-array name="jmdict_tags"> | |
36 | - | <item id="MA">martial arts term</item> | |
37 | - | <item id="X">rude or X-rated term (not displayed in educational software)</item> | |
38 | - | <item id="abbr">abbreviation</item> | |
39 | - | <item>adjective (keiyoushi)</item> | |
40 | - | <item>adjective (keiyoushi) - yoi/ii class</item> | |
41 | - | <item>adjectival nouns or quasi-adjectives (keiyodoshi)</item> | |
42 | - | <item>nouns which may take the genitive case particle \'no\'</item> | |
43 | - | <item>pre-noun adjectival (rentaishi)</item> | |
44 | - | <item>\'taru\' adjective</item> | |
45 | - | <item>noun or verb acting prenominally</item> | |
46 | - | <item>adverb (fukushi)</item> | |
47 | - | <item>adverb taking the \'to\' particle</item> | |
48 | - | <item>archaism</item> | |
49 | - | <item>ateji (phonetic) reading</item> | |
50 | - | <item>auxiliary</item> | |
51 | - | <item>auxiliary verb</item> | |
52 | - | <item>auxiliary adjective</item> | |
53 | - | <item>Buddhist term</item> | |
54 | - | <item>chemistry term</item> | |
55 | - | <item>children\'s language</item> | |
56 | - | <item>colloquialism</item> | |
57 | - | <item>computer terminology</item> | |
58 | - | <item>conjunction</item> | |
59 | - | <item>copula</item> | |
60 | - | <item>counter</item> | |
61 | - | <item>derogatory</item> | |
62 | - | <item>exclusively kanji</item> | |
63 | - | <item>exclusively kana</item> | |
64 | - | <item>expressions (phrases, clauses, etc.)</item> | |
65 | - | <item>familiar language</item> | |
66 | - | <item>female term or language</item> | |
67 | - | <item>food term</item> | |
68 | - | <item>geometry term</item> | |
69 | - | <item>gikun (meaning as reading) or jukujikun (special kanji reading)</item> | |
70 | - | <item>honorific or respectful (sonkeigo) language</item> | |
71 | - | <item>humble (kenjougo) language</item> | |
72 | - | <item>word containing irregular kanji usage</item> | |
73 | - | <item>idiomatic expression</item> | |
74 | - | <item>word containing irregular kana usage</item> | |
75 | - | <item>interjection (kandoushi)</item> | |
76 | - | <item>irregular okurigana usage</item> | |
77 | - | <item>irregular verb</item> | |
78 | - | <item>linguistics terminology</item> | |
79 | - | <item>manga slang</item> | |
80 | - | <item>male term or language</item> | |
81 | - | <item>male slang</item> | |
82 | - | <item>mathematics</item> | |
83 | - | <item>military</item> | |
84 | - | <item>noun (common) (futsuumeishi)</item> | |
85 | - | <item>adverbial noun (fukushitekimeishi)</item> | |
86 | - | <item>noun, used as a suffix</item> | |
87 | - | <item>noun, used as a prefix</item> | |
88 | - | <item>noun (temporal) (jisoumeishi)</item> | |
89 | - | <item>numeric</item> | |
90 | - | <item>word containing out-dated kanji</item> | |
91 | - | <item>obsolete term</item> | |
92 | - | <item>obscure term</item> | |
93 | - | <item>out-dated or obsolete kana usage</item> | |
94 | - | <item>old or irregular kana form</item> | |
95 | - | <item>onomatopoeic or mimetic word</item> | |
96 | - | <item>pronoun</item> | |
97 | - | <item>poetical term</item> | |
98 | - | <item>polite (teineigo) language</item> | |
99 | - | <item>prefix</item> | |
100 | - | <item>proverb</item> | |
101 | - | <item>particle</item> | |
102 | - | <item>physics terminology</item> | |
103 | - | <item>quotation</item> | |
104 | - | <item>rare</item> | |
105 | - | <item>sensitive</item> | |
106 | - | <item>slang</item> | |
107 | - | <item>suffix</item> | |
108 | - | <item>word usually written using kanji alone</item> | |
109 | - | <item>word usually written using kana alone</item> | |
110 | - | <item>unclassified</item> | |
111 | - | <item>yojijukugo</item> | |
112 | - | <item>Ichidan verb</item> | |
113 | - | <item>Ichidan verb - kureru special class</item> | |
114 | - | <item>Nidan verb with \'u\' ending (archaic)</item> | |
115 | - | <item>Yodan verb with \'hu/fu\' ending (archaic)</item> | |
116 | - | <item>Yodan verb with \'ru\' ending (archaic)</item> | |
117 | - | <item>Godan verb - -aru special class</item> | |
118 | - | <item>Godan verb with \'bu\' ending</item> | |
119 | - | <item>Godan verb with \'gu\' ending</item> | |
120 | - | <item>Godan verb with \'ku\' ending</item> | |
121 | - | <item>Godan verb - Iku/Yuku special class</item> | |
122 | - | <item>Godan verb with \'mu\' ending</item> | |
123 | - | <item>Godan verb with \'nu\' ending</item> | |
124 | - | <item>Godan verb with \'ru\' ending</item> | |
125 | - | <item>Godan verb with \'ru\' ending (irregular verb)</item> | |
126 | - | <item>Godan verb with \'su\' ending</item> | |
127 | - | <item>Godan verb with \'tsu\' ending</item> | |
128 | - | <item>Godan verb with \'u\' ending</item> | |
129 | - | <item>Godan verb with \'u\' ending (special class)</item> | |
130 | - | <item>Godan verb - Uru old class verb (old form of Eru)</item> | |
131 | - | <item>Ichidan verb - zuru verb (alternative form of -jiru verbs)</item> | |
132 | - | <item>intransitive verb</item> | |
133 | - | <item>Kuru verb - special class</item> | |
134 | - | <item>irregular nu verb</item> | |
135 | - | <item>irregular ru verb, plain form ends with -ri</item> | |
136 | - | <item>noun or participle which takes the aux. verb suru</item> | |
137 | - | <item>su verb - precursor to the modern suru</item> | |
138 | - | <item>suru verb - special class</item> | |
139 | - | <item>suru verb - included</item> | |
140 | - | <item>Kyoto-ben</item> | |
141 | - | <item>Osaka-ben</item> | |
142 | - | <item>Kansai-ben</item> | |
143 | - | <item>Kantou-ben</item> | |
144 | - | <item>Tosa-ben</item> | |
145 | - | <item>Touhoku-ben</item> | |
146 | - | <item>Tsugaru-ben</item> | |
147 | - | <item>Kyuushuu-ben</item> | |
148 | - | <item>Ryuukyuu-ben</item> | |
149 | - | <item>Nagano-ben</item> | |
150 | - | <item>Hokkaido-ben</item> | |
151 | - | <item>transitive verb</item> | |
152 | - | <item>vulgar expression or word</item> | |
153 | - | <item>\'kari\' adjective (archaic)</item> | |
154 | - | <item>\'ku\' adjective (archaic)</item> | |
155 | - | <item>\'shiku\' adjective (archaic)</item> | |
156 | - | <item>archaic/formal form of na-adjective</item> | |
157 | - | <item>proper noun</item> | |
158 | - | <item>verb unspecified</item> | |
159 | - | <item>Yodan verb with \'ku\' ending (archaic)</item> | |
160 | - | <item>Yodan verb with \'gu\' ending (archaic)</item> | |
161 | - | <item>Yodan verb with \'su\' ending (archaic)</item> | |
162 | - | <item>Yodan verb with \'tsu\' ending (archaic)</item> | |
163 | - | <item>Yodan verb with \'nu\' ending (archaic)</item> | |
164 | - | <item>Yodan verb with \'bu\' ending (archaic)</item> | |
165 | - | <item>Yodan verb with \'mu\' ending (archaic)</item> | |
166 | - | <item>Nidan verb (upper class) with \'ku\' ending (archaic)</item> | |
167 | - | <item>Nidan verb (upper class) with \'gu\' ending (archaic)</item> | |
168 | - | <item>Nidan verb (upper class) with \'tsu\' ending (archaic)</item> | |
169 | - | <item>Nidan verb (upper class) with \'dzu\' ending (archaic)</item> | |
170 | - | <item>Nidan verb (upper class) with \'hu/fu\' ending (archaic)</item> | |
171 | - | <item>Nidan verb (upper class) with \'bu\' ending (archaic)</item> | |
172 | - | <item>Nidan verb (upper class) with \'mu\' ending (archaic)</item> | |
173 | - | <item>Nidan verb (upper class) with \'yu\' ending (archaic)</item> | |
174 | - | <item>Nidan verb (upper class) with \'ru\' ending (archaic)</item> | |
175 | - | <item>Nidan verb (lower class) with \'ku\' ending (archaic)</item> | |
176 | - | <item>Nidan verb (lower class) with \'gu\' ending (archaic)</item> | |
177 | - | <item>Nidan verb (lower class) with \'su\' ending (archaic)</item> | |
178 | - | <item>Nidan verb (lower class) with \'zu\' ending (archaic)</item> | |
179 | - | <item>Nidan verb (lower class) with \'tsu\' ending (archaic)</item> | |
180 | - | <item>Nidan verb (lower class) with \'dzu\' ending (archaic)</item> | |
181 | - | <item>Nidan verb (lower class) with \'nu\' ending (archaic)</item> | |
182 | - | <item>Nidan verb (lower class) with \'hu/fu\' ending (archaic)</item> | |
183 | - | <item>Nidan verb (lower class) with \'bu\' ending (archaic)</item> | |
184 | - | <item>Nidan verb (lower class) with \'mu\' ending (archaic)</item> | |
185 | - | <item>Nidan verb (lower class) with \'yu\' ending (archaic)</item> | |
186 | - | <item>Nidan verb (lower class) with \'ru\' ending (archaic)</item> | |
187 | - | <item>Nidan verb (lower class) with \'u\' ending and \'we\' conjugation (archaic)</item> | |
188 | - | <item>architecture term</item> | |
189 | - | <item>astronomy, etc. term</item> | |
190 | - | <item>baseball term</item> | |
191 | - | <item>biology term</item> | |
192 | - | <item>botany term</item> | |
193 | - | <item>business term</item> | |
194 | - | <item>economics term</item> | |
195 | - | <item>engineering term</item> | |
196 | - | <item>finance term</item> | |
197 | - | <item>geology, etc. term</item> | |
198 | - | <item>law, etc. term</item> | |
199 | - | <item>mahjong term</item> | |
200 | - | <item>medicine, etc. term</item> | |
201 | - | <item>music term</item> | |
202 | - | <item>Shinto term</item> | |
203 | - | <item>shogi term</item> | |
204 | - | <item>sports term</item> | |
205 | - | <item>sumo term</item> | |
206 | - | <item>zoology term</item> | |
207 | - | <item>jocular, humorous term</item> | |
208 | - | <item>anatomical term</item> | |
209 | - | </string-array> | |
210 | - | ||
211 | 40 | <!-- About activity --> | |
212 | 41 | <string name="nani_about">Hi, tyreunom here!\n | |
213 | 42 | I\'m a japanese learner and programmer. I found that there were no app for my use case, |