Support romaji input
app/build.gradle
| 23 | 23 | implementation 'com.android.support:appcompat-v7:28.0.0' | |
| 24 | 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' | |
| 25 | 25 | implementation 'com.android.support:design:28.0.0' | |
| 26 | + | implementation 'com.andree-surya:moji4j:1.0.0' | |
| 27 | + | implementation project(path: ':furiganatextview') | |
| 26 | 28 | testImplementation 'junit:junit:4.12' | |
| 27 | 29 | androidTestImplementation 'com.android.support.test:runner:1.0.2' | |
| 28 | 30 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | |
| 29 | - | implementation project(path: ':furiganatextview') | |
| 30 | 31 | } |
app/src/main/java/eu/lepiller/nani/MainActivity.java
| 15 | 15 | import android.widget.LinearLayout; | |
| 16 | 16 | import android.widget.TextView; | |
| 17 | 17 | ||
| 18 | + | import com.moji4j.MojiConverter; | |
| 19 | + | import com.moji4j.MojiDetector; | |
| 20 | + | ||
| 18 | 21 | import java.util.ArrayList; | |
| 19 | 22 | ||
| 20 | 23 | import eu.lepiller.nani.dictionary.DictionaryException; | |
… | |||
| 28 | 31 | private LinearLayout result_view; | |
| 29 | 32 | private Button search_button; | |
| 30 | 33 | private TextView feedback_text; | |
| 34 | + | private EditText search_form; | |
| 31 | 35 | ||
| 32 | 36 | @Override | |
| 33 | 37 | protected void onCreate(Bundle savedInstanceState) { | |
… | |||
| 39 | 43 | search_button = findViewById(R.id.search_button); | |
| 40 | 44 | result_view = findViewById(R.id.results_view); | |
| 41 | 45 | feedback_text = findViewById(R.id.feedback); | |
| 42 | - | final EditText search_form = findViewById(R.id.search_form); | |
| 46 | + | search_form = findViewById(R.id.search_form); | |
| 43 | 47 | ||
| 44 | 48 | search_button.setOnClickListener(new View.OnClickListener() { | |
| 45 | 49 | @Override | |
… | |||
| 77 | 81 | return new SearchResult(e); | |
| 78 | 82 | } | |
| 79 | 83 | ||
| 80 | - | return new SearchResult(searchResult); | |
| 84 | + | ||
| 85 | + | if(searchResult == null || searchResult.size() == 0) { | |
| 86 | + | MojiConverter converter = new MojiConverter(); | |
| 87 | + | try { | |
| 88 | + | searchResult = DictionaryFactory.search(converter.convertRomajiToHiragana(text)); | |
| 89 | + | } catch (DictionaryException e) { | |
| 90 | + | return new SearchResult(e); | |
| 91 | + | } | |
| 92 | + | ||
| 93 | + | return new SearchResult(searchResult, text, true); | |
| 94 | + | } else { | |
| 95 | + | return new SearchResult(searchResult, text, false); | |
| 96 | + | } | |
| 81 | 97 | } | |
| 82 | 98 | ||
| 83 | 99 | @Override | |
… | |||
| 101 | 117 | return; | |
| 102 | 118 | } | |
| 103 | 119 | ||
| 120 | + | feedback_text.setText(""); | |
| 121 | + | ||
| 104 | 122 | ArrayList<Result> searchResult = r.getResults(); | |
| 123 | + | MojiDetector detector = new MojiDetector(); | |
| 124 | + | String text = r.getText(); | |
| 125 | + | if(searchResult != null && searchResult.size()>1 && !r.isConverted() && detector.hasLatin(text)) { | |
| 126 | + | MojiConverter converter = new MojiConverter(); | |
| 127 | + | final String moji = converter.convertRomajiToHiragana(r.getText()); | |
| 128 | + | feedback_text.setText(String.format(getString(R.string.feedback_didyoumean), moji)); | |
| 129 | + | ||
| 130 | + | feedback_text.setOnClickListener(new View.OnClickListener() { | |
| 131 | + | @Override | |
| 132 | + | public void onClick(View v) { | |
| 133 | + | search_form.setText(moji); | |
| 134 | + | feedback_text.setOnClickListener(null); | |
| 135 | + | search_button.callOnClick(); | |
| 136 | + | } | |
| 137 | + | }); | |
| 138 | + | } | |
| 105 | 139 | showResults(searchResult); | |
| 106 | 140 | } | |
| 107 | 141 | ||
… | |||
| 110 | 144 | feedback_text.setText(R.string.feedback_no_result); | |
| 111 | 145 | return; | |
| 112 | 146 | } | |
| 113 | - | feedback_text.setText(""); | |
| 114 | 147 | ||
| 115 | 148 | int num = 0; | |
| 116 | 149 | for(Result result: searchResult) { | |
app/src/main/java/eu/lepiller/nani/SearchResult.java
| 8 | 8 | public class SearchResult { | |
| 9 | 9 | private ArrayList<Result> results; | |
| 10 | 10 | private DictionaryException exception; | |
| 11 | + | private boolean converted; | |
| 12 | + | private String text; | |
| 11 | 13 | ||
| 12 | - | SearchResult(ArrayList<Result> results) { | |
| 14 | + | SearchResult(ArrayList<Result> results, String text, boolean converted) { | |
| 13 | 15 | this.results = results; | |
| 16 | + | this.converted = converted; | |
| 17 | + | this.text = text; | |
| 14 | 18 | } | |
| 15 | 19 | ||
| 16 | 20 | SearchResult(DictionaryException e) { | |
… | |||
| 28 | 32 | ArrayList<Result> getResults() { | |
| 29 | 33 | return results; | |
| 30 | 34 | } | |
| 35 | + | ||
| 36 | + | boolean isConverted() { | |
| 37 | + | return converted; | |
| 38 | + | } | |
| 39 | + | ||
| 40 | + | String getText() { | |
| 41 | + | return text; | |
| 42 | + | } | |
| 31 | 43 | } | |
app/src/main/res/values-fr/strings.xml
| 22 | 22 | <string name="dictionary_size">Taille r??elle : %d???Mo</string> | |
| 23 | 23 | <string name="feedback_no_result">Pas de r??sultat</string> | |
| 24 | 24 | <string name="feedback_progress">Recherche???</string> | |
| 25 | + | <string name="feedback_didyoumean">Vouliez-vous dire ?? %s ?? ?</string> | |
| 25 | 26 | ||
| 26 | 27 | <!-- Dictionnary descriptions --> | |
| 27 | 28 |
app/src/main/res/values/strings.xml
| 19 | 19 | <string name="dictionary_size">Actual size: %dMB</string> | |
| 20 | 20 | <string name="feedback_no_result">No result</string> | |
| 21 | 21 | <string name="feedback_progress">Searching...</string> | |
| 22 | + | <string name="feedback_didyoumean">Did you mean "%s"?</string> | |
| 22 | 23 | ||
| 23 | 24 | <!-- Dictionnary descriptions --> | |
| 24 | 25 | <string name="dico_jmdict_e">Japanese/English dictionary from the Electronic Dictionary Research and Development Group.\n~56 MB, ~180,000 entries.</string> |