Add pronunciation preference
app/src/main/java/eu/lepiller/nani/MainActivity.java
37 | 37 | private SearchView search_form; | |
38 | 38 | private static ArrayList<Result> savedResults; | |
39 | 39 | private RadicalSelectorView radical_selector; | |
40 | + | private String readingStyle = "furigana"; | |
40 | 41 | ||
41 | 42 | private static final String TAG = "MAIN"; | |
42 | 43 | ||
… | |||
61 | 62 | PreferenceManager.getDefaultSharedPreferences(this); | |
62 | 63 | sharedPref.registerOnSharedPreferenceChangeListener(this); | |
63 | 64 | int radSizePref = getRadSizePref(sharedPref); | |
65 | + | readingStyle = getReadingSizePref(sharedPref); | |
64 | 66 | ||
65 | 67 | try { | |
66 | 68 | radical_selector.setRadSize(radSizePref); | |
… | |||
140 | 142 | ||
141 | 143 | @Override | |
142 | 144 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { | |
145 | + | Log.d("MAIN", key + " preference changed."); | |
143 | 146 | if(key.compareTo(SettingsActivity.KEY_PREF_RAD_SIZE) == 0) { | |
144 | 147 | radical_selector.setRadSize(getRadSizePref(sharedPreferences)); | |
148 | + | } else if(key.compareTo(SettingsActivity.KEY_PREF_READING_STYLE) == 0) { | |
149 | + | readingStyle = getReadingSizePref(sharedPreferences); | |
145 | 150 | } | |
146 | 151 | } | |
147 | 152 | ||
… | |||
152 | 157 | return Integer.parseInt(prefRadSize); | |
153 | 158 | } | |
154 | 159 | ||
160 | + | private String getReadingSizePref(SharedPreferences sharedPreferences) { | |
161 | + | String prefReadingStyle = sharedPreferences.getString(SettingsActivity.KEY_PREF_READING_STYLE, "furigana"); | |
162 | + | if(prefReadingStyle == null) | |
163 | + | prefReadingStyle = "furigana"; | |
164 | + | return prefReadingStyle; | |
165 | + | } | |
166 | + | ||
155 | 167 | private static class SearchTask extends AsyncTask<String, Integer, SearchResult> { | |
156 | 168 | OnTaskCompleted<SearchResult> callback; | |
157 | 169 | SearchTask(OnTaskCompleted<SearchResult> callback) { | |
… | |||
266 | 278 | View child_result = getLayoutInflater().inflate(R.layout.layout_result, result_view, false); | |
267 | 279 | ||
268 | 280 | FuriganaTextView kanji_view = child_result.findViewById(R.id.kanji_view); | |
281 | + | TextView reading_view = child_result.findViewById(R.id.reading_view); | |
269 | 282 | LinearLayout senses_view = child_result.findViewById(R.id.sense_view); | |
270 | 283 | TextView additional_info = child_result.findViewById(R.id.additional_info_view); | |
271 | 284 | TextView pitch_view = child_result.findViewById(R.id.pitch_view); | |
272 | 285 | ||
273 | 286 | // Populate the data into the template view using the data object | |
274 | - | kanji_view.setFuriganaText(result.getKanjiFurigana()); | |
287 | + | if(readingStyle.compareTo("furigana") == 0) { | |
288 | + | kanji_view.setFuriganaText(result.getKanjiFurigana()); | |
289 | + | } else { | |
290 | + | kanji_view.setFuriganaText(result.getKanji()); | |
291 | + | reading_view.setVisibility(View.VISIBLE); | |
292 | + | reading_view.setText(readingStyle.compareTo("kana") == 0? result.getReading(): result.getRomajiReading()); | |
293 | + | } | |
275 | 294 | ||
276 | 295 | // If pitch information is available, make it visible | |
277 | 296 | String pitch = result.getPitch(); |
app/src/main/java/eu/lepiller/nani/SettingsActivity.java
6 | 6 | ||
7 | 7 | public class SettingsActivity extends AppCompatActivity { | |
8 | 8 | public static final String KEY_PREF_RAD_SIZE = "rad_size"; | |
9 | + | public static final String KEY_PREF_READING_STYLE = "reading_style"; | |
9 | 10 | ||
10 | 11 | @Override | |
11 | 12 | protected void onCreate(Bundle savedInstanceState) { |
app/src/main/java/eu/lepiller/nani/result/Result.java
2 | 2 | ||
3 | 3 | import android.util.Log; | |
4 | 4 | ||
5 | + | import com.moji4j.MojiConverter; | |
6 | + | ||
5 | 7 | import java.util.ArrayList; | |
6 | 8 | import java.util.List; | |
7 | 9 | import java.util.regex.Matcher; | |
… | |||
115 | 117 | return reading; | |
116 | 118 | } | |
117 | 119 | ||
120 | + | public String getRomajiReading() { | |
121 | + | String reading = getReading(); | |
122 | + | MojiConverter converter = new MojiConverter(); | |
123 | + | return converter.convertKanaToRomaji(reading); | |
124 | + | } | |
125 | + | ||
118 | 126 | public String getPitch() { | |
119 | 127 | if(readings.size() > 0) { | |
120 | 128 | ArrayList<String> pitches = readings.get(0).pitches; |
app/src/main/res/drawable/ic_reading.xml unknown status 1
1 | + | <vector xmlns:android="http://schemas.android.com/apk/res/android" | |
2 | + | android:width="32dp" | |
3 | + | android:height="32dp" | |
4 | + | android:viewportWidth="32" | |
5 | + | android:viewportHeight="32"> | |
6 | + | <path | |
7 | + | android:pathData="M16,16m-16,0a16,16 0,1 1,32 0a16,16 0,1 1,-32 0" | |
8 | + | android:strokeLineJoin="round" | |
9 | + | android:strokeWidth="0.264999" | |
10 | + | android:fillColor="#e6e6e6" | |
11 | + | android:strokeLineCap="round"/> | |
12 | + | <path | |
13 | + | android:fillColor="#1a1a1a" | |
14 | + | android:pathData="m22.0309,8.1927q-0.1895,-0.548 -0.6633,-0.8699l0.3127,-0.3219q0.8528,0.3306 1.3929,1.2092 2.1984,0.2349 3.506,1.27 1.3645,1.0874 1.3645,2.8446 0,2.3922 -2.6627,3.7405 -1.8004,0.9134 -4.4536,1.2004l-0.1611,-0.5045q3.2123,-0.6959 4.662,-1.8964 1.3361,-1.1048 1.3361,-2.7315 0,-1.4266 -1.2224,-2.3661 -0.9381,-0.722 -2.331,-0.9482 -0.1706,0.8786 -1.175,2.2965 -1.2318,1.5832 -2.549,2.6184 0.0948,0.435 0.2748,0.7829 0.2274,0.5567 0.2274,0.7133 0,0.7655 -0.5591,0.7655 -0.4548,0 -0.8528,-1.5484 -2.2363,1.6354 -3.705,1.6354 -1.5351,0 -1.5351,-1.6006 0,-1.8007 1.6582,-3.4274 1.3076,-1.2787 3.2123,-2.0616 0.0474,-0.7655 0.1706,-2.3139 -0.597,0.0348 -1.2982,0.0348 -1.2224,0 -1.8572,-0.348 -0.5496,-0.2958 -0.9002,-0.9656l0.4548,-0.3045q0.5875,0.8351 2.1131,0.8351 0.7486,0 1.5919,-0.087 0.199,-1.5136 0.199,-1.9051 0,-0.3132 -0.2558,-0.5045 -0.2179,-0.174 -0.8339,-0.4262l0.2085,-0.4088q2.2742,0.2784 2.2742,1.0178 0,0.2349 -0.2179,0.6785 -0.199,0.3393 -0.3885,1.4353 1.1939,-0.1827 2.7195,-0.6698 0.2748,-0.0783 0.6254,-0.2871 0.3601,-0.2349 1.0044,-0.2349 0.7581,0 0.7581,0.4436 0,0.3393 -0.3696,0.4871 -1.8383,0.6263 -4.8705,1.07 -0.1516,0.9221 -0.2179,2.1486 1.3266,-0.4262 3.0133,-0.4958zM22.0689,8.7842q-1.5066,0.0783 -3.0891,0.6002 -0.1042,1.7572 0.199,3.5666 1.0897,-1.0439 2.1889,-2.6532 0.5875,-0.7916 0.7012,-1.5136zM18.307,13.6295q-0.2464,-1.6441 -0.2179,-3.9058 -1.5635,0.7307 -2.6721,2.0442 -1.0897,1.2874 -1.0897,2.5401 0,0.8525 0.8907,0.8525 0.4359,0 1.3455,-0.4523 0.8812,-0.435 1.7435,-1.0787z" | |
15 | + | android:strokeWidth="0"/> | |
16 | + | <path | |
17 | + | android:fillColor="#1a1a1a" | |
18 | + | android:pathData="m11.6158,22.3628q-2.1131,0 -2.928,0.4436 -0.8149,0.4437 -0.8149,1.5136 0,0.8525 0.6064,1.357 0.6159,0.4958 1.6677,0.4958 1.4498,0 2.3215,-0.9395 0.8812,-0.9482 0.8812,-2.514v-0.3566zM15.0934,21.7017v5.5586h-1.7435v-1.4788q-0.597,0.8873 -1.4877,1.3135 -0.8907,0.4175 -2.1794,0.4175 -1.6298,0 -2.5963,-0.8351 -0.957,-0.8438 -0.957,-2.253 0,-1.6441 1.1939,-2.4792 1.2034,-0.8351 3.5818,-0.8351h2.4447L13.3499,20.9535q0,-1.1048 -0.796,-1.705 -0.7865,-0.6089 -2.2173,-0.6089 -0.9097,0 -1.772,0.2001 -0.8623,0.2001 -1.6582,0.6002v-1.4788q0.957,-0.3393 1.8572,-0.5045 0.9002,-0.174 1.753,-0.174 2.3026,0 3.4397,1.0961 1.1371,1.0961 1.1371,3.323z" | |
19 | + | android:strokeWidth="0"/> | |
20 | + | </vector> |
app/src/main/res/layout/layout_result.xml
13 | 13 | android:layout_gravity="center" | |
14 | 14 | android:orientation="horizontal"> | |
15 | 15 | ||
16 | - | ||
17 | - | <se.fekete.furiganatextview.furiganaview.FuriganaTextView | |
18 | - | android:id="@+id/kanji_view" | |
19 | - | android:layout_width="match_parent" | |
16 | + | <LinearLayout | |
17 | + | android:layout_width="wrap_content" | |
20 | 18 | android:layout_height="wrap_content" | |
21 | - | android:layout_marginLeft="8dp" | |
22 | - | android:layout_marginStart="8dp" | |
23 | - | android:layout_marginRight="8dp" | |
24 | - | android:layout_marginEnd="8dp" | |
25 | - | android:textAlignment="center" | |
26 | - | android:contentDescription="@string/kanji_description" | |
27 | - | android:textIsSelectable="true" | |
28 | - | app:contains_ruby_tags="true" | |
29 | - | android:textSize="@dimen/title_size" | |
30 | - | android:gravity="center_horizontal" /> | |
19 | + | android:layout_gravity="center" | |
20 | + | android:orientation="vertical"> | |
21 | + | <se.fekete.furiganatextview.furiganaview.FuriganaTextView | |
22 | + | android:id="@+id/kanji_view" | |
23 | + | android:layout_width="match_parent" | |
24 | + | android:layout_height="wrap_content" | |
25 | + | android:layout_marginLeft="8dp" | |
26 | + | android:layout_marginStart="8dp" | |
27 | + | android:layout_marginRight="8dp" | |
28 | + | android:layout_marginEnd="8dp" | |
29 | + | android:textAlignment="center" | |
30 | + | android:contentDescription="@string/kanji_description" | |
31 | + | android:textIsSelectable="true" | |
32 | + | app:contains_ruby_tags="true" | |
33 | + | android:textSize="@dimen/title_size" | |
34 | + | android:gravity="center_horizontal" /> | |
35 | + | ||
36 | + | <TextView | |
37 | + | android:id="@+id/reading_view" | |
38 | + | android:layout_width="match_parent" | |
39 | + | android:layout_height="wrap_content" | |
40 | + | android:layout_marginTop="8dp" | |
41 | + | android:layout_marginLeft="8dp" | |
42 | + | android:layout_marginStart="8dp" | |
43 | + | android:layout_marginRight="8dp" | |
44 | + | android:layout_marginEnd="8dp" | |
45 | + | android:textAlignment="center" | |
46 | + | android:contentDescription="@string/kanji_description" | |
47 | + | android:textIsSelectable="true" | |
48 | + | android:gravity="center_horizontal" | |
49 | + | android:visibility="gone" /> | |
50 | + | </LinearLayout> | |
31 | 51 | ||
32 | 52 | <TextView | |
33 | 53 | android:layout_width="wrap_content" |
app/src/main/res/values/strings.xml
51 | 51 | <item>122</item> | |
52 | 52 | <item>96</item> | |
53 | 53 | </string-array> | |
54 | + | <string name="pref_reading_style">Display style for pronunciation</string> | |
55 | + | <string-array name="pref_reading_style_choice"> | |
56 | + | <item>Furigana</item> | |
57 | + | <item>Kana</item> | |
58 | + | <item>Romaji</item> | |
59 | + | </string-array> | |
60 | + | <string-array name="pref_reading_style_values" translatable="false"> | |
61 | + | <item>furigana</item> | |
62 | + | <item>kana</item> | |
63 | + | <item>romaji</item> | |
64 | + | </string-array> | |
54 | 65 | ||
55 | 66 | <!-- Dictionnary descriptions --> | |
56 | 67 | <string name="error_dico_url">Error fetching dictionary list: malformed URL.</string> |
app/src/main/res/xml/preferences.xml
7 | 7 | android:title="@string/pref_rad_size" | |
8 | 8 | android:defaultValue="122" | |
9 | 9 | android:icon="@drawable/ic_rad"/> | |
10 | + | <ListPreference | |
11 | + | android:entries="@array/pref_reading_style_choice" | |
12 | + | android:entryValues="@array/pref_reading_style_values" | |
13 | + | android:key="reading_style" | |
14 | + | android:title="@string/pref_reading_style" | |
15 | + | android:defaultValue="furigana" | |
16 | + | android:icon="@drawable/ic_reading"/> | |
10 | 17 | </PreferenceScreen> | |
10 | 17 | = | |
11 | 18 | = | \ No newline at end of file |