Added initial Italian support + more:
* Added "word at cursor" search when adding new word. * Attempted crashfix for weird suggestion building crash
This commit is contained in:
parent
81d3bd65bb
commit
1b15cd0928
15 changed files with 110695 additions and 17 deletions
|
|
@ -41,8 +41,9 @@ public class CharMap {
|
|||
// add extra characters for German and French maps.
|
||||
enMap.put('€', 1); enMap.put('ß', 7); // German chars
|
||||
enMap.put('î', 4); enMap.put('ù', 8); // French chars
|
||||
Map<Character, Integer> endefrmap = Collections.unmodifiableMap(enMap);
|
||||
CHARTABLE.add(0, endefrmap);
|
||||
enMap.put('ì', 4); enMap.put('ò', 8); // Italian chars
|
||||
Map<Character, Integer> endefritmap = Collections.unmodifiableMap(enMap);
|
||||
CHARTABLE.add(0, endefritmap);
|
||||
|
||||
// Russian
|
||||
Map<Character, Integer> ruMap = new HashMap<Character, Integer>();
|
||||
|
|
@ -73,8 +74,9 @@ public class CharMap {
|
|||
ruMap.put('0', 0);
|
||||
CHARTABLE.add(1, Collections.unmodifiableMap(ruMap));
|
||||
|
||||
CHARTABLE.add(2, Collections.unmodifiableMap(endefrmap));
|
||||
CHARTABLE.add(3, Collections.unmodifiableMap(endefrmap));
|
||||
CHARTABLE.add(2, Collections.unmodifiableMap(endefritmap));
|
||||
CHARTABLE.add(3, Collections.unmodifiableMap(endefritmap));
|
||||
CHARTABLE.add(4, Collections.unmodifiableMap(endefritmap));
|
||||
}
|
||||
|
||||
protected static final char[][] ENT9TABLE = { { '0', '+' },
|
||||
|
|
@ -116,13 +118,23 @@ public class CharMap {
|
|||
{ 't', 'u', 'v', 'T', 'U', 'V', 'ü', 'Ü', 'û', 'Û', '8' },
|
||||
{ 'w', 'x', 'y', 'z', 'W', 'X', 'Y', 'Z', '9' },
|
||||
{ '\n' } };
|
||||
protected static final char[][][] T9TABLE = { ENT9TABLE, RUT9TABLE, DET9TABLE, FRT9TABLE };
|
||||
|
||||
protected static final char[][] ITT9TABLE = {
|
||||
{ ' ', '+', '0' },
|
||||
{ '.', ',', '?', '!', ':', ';', '"', '/', '-', '@', '^', '€', '$', '%', '&', '*', '(', ')', '_', '1' },
|
||||
{ 'a', 'b', 'c', 'A', 'B', 'C', 'à', 'À', '2' }, { 'd', 'e', 'f', 'D', 'E', 'F', 'é', 'è', 'É', 'È', '3' },
|
||||
{ 'g', 'h', 'i', 'G', 'H', 'I', 'ì', 'Ì', '4' }, { 'j', 'k', 'l', 'J', 'K', 'L', '5' },
|
||||
{ 'm', 'n', 'o', 'M', 'N', 'O', 'ò', 'Ò', '6' }, { 'p', 'q', 'r', 's', 'P', 'Q', 'R', 'S', '7' },
|
||||
{ 't', 'u', 'v', 'T', 'U', 'V', 'ù', 'Ù', '8' }, { 'w', 'x', 'y', 'z', 'W', 'X', 'Y', 'Z', '9' },
|
||||
{ '\n' } };
|
||||
protected static final char[][][] T9TABLE = { ENT9TABLE, RUT9TABLE, DET9TABLE, FRT9TABLE, ITT9TABLE };
|
||||
|
||||
protected static final int[] ENT9CAPSTART = { 0, 0, 3, 3, 3, 3, 3, 4, 3, 4, 0 };
|
||||
protected static final int [] RUT9CAPSTART = {0, 0, 4, 5, 4, 4, 4, 4, 4, 4, 0};
|
||||
protected static final int[] DET9CAPSTART = { 0, 0, 3, 3, 3, 3, 3, 4, 3, 4, 0 };
|
||||
protected static final int[] FRT9CAPSTART = { 0, 0, 3, 3, 3, 3, 3, 4, 3, 4, 0 };
|
||||
protected static final int[][] T9CAPSTART = {ENT9CAPSTART, RUT9CAPSTART, DET9CAPSTART, FRT9CAPSTART};
|
||||
protected static final int[] ITT9CAPSTART = { 0, 0, 3, 3, 3, 3, 3, 4, 3, 4, 0 };
|
||||
protected static final int[][] T9CAPSTART = {ENT9CAPSTART, RUT9CAPSTART, DET9CAPSTART, FRT9CAPSTART, ITT9CAPSTART};
|
||||
|
||||
protected static String getStringSequence(String word, LANGUAGE lang) {
|
||||
StringBuilder seq = new StringBuilder();
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public class LangHelper {
|
|||
// the same order as arrays.xml/pref_lang_values, and id is the identifier used in
|
||||
// the database and such. id should never change unless database update is done.
|
||||
// id MUST increment in doubles (as the enabled languages are stored as an integer)
|
||||
NONE(-1, -1), EN(0,1), RU(1,2), DE(2,4), FR(3,8);
|
||||
NONE(-1, -1), EN(0,1), RU(1,2), DE(2,4), FR(3,8), IT(4,16);
|
||||
public final int index;
|
||||
public final int id;
|
||||
// lookup map
|
||||
|
|
@ -25,7 +25,7 @@ public class LangHelper {
|
|||
public static LANGUAGE get(int i) { return lookup.get(i);}
|
||||
}
|
||||
|
||||
protected static final Locale[] LOCALES = {Locale.ENGLISH, RUSSIAN, Locale.GERMAN, Locale.FRENCH};
|
||||
protected static final Locale[] LOCALES = {Locale.ENGLISH, RUSSIAN, Locale.GERMAN, Locale.FRENCH, Locale.ITALIAN};
|
||||
//protected static final String[] LANGS = {"EN", "RU", "DE"};
|
||||
|
||||
public static final int LANG_DEFAULT = LANGUAGE.EN.id;
|
||||
|
|
@ -67,7 +67,12 @@ public class LangHelper {
|
|||
{R.drawable.ime_en_text_lower, R.drawable.ime_en_text_single, R.drawable.ime_en_text_upper}, //TEXT
|
||||
{R.drawable.ime_number}, //NUM
|
||||
},
|
||||
|
||||
{
|
||||
// Italian resources
|
||||
{R.drawable.ime_it_lang_lower, R.drawable.ime_it_lang_single, R.drawable.ime_it_lang_upper}, //LANG
|
||||
{R.drawable.ime_en_text_lower, R.drawable.ime_en_text_single, R.drawable.ime_en_text_upper}, //TEXT
|
||||
{R.drawable.ime_number}, //NUM
|
||||
},
|
||||
};
|
||||
|
||||
public static LANGUAGE[] buildLangs(int i) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import java.util.AbstractList;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
public class TraditionalT9 extends InputMethodService implements
|
||||
KeyboardView.OnKeyboardActionListener {
|
||||
|
||||
|
|
@ -176,12 +178,42 @@ public class TraditionalT9 extends InputMethodService implements
|
|||
mComposingI.setLength(0);
|
||||
mWordFound = true;
|
||||
}
|
||||
|
||||
private String getSurroundingWord() {
|
||||
CharSequence before = currentInputConnection.getTextBeforeCursor(50, 0);
|
||||
CharSequence after = currentInputConnection.getTextAfterCursor(50, 0);
|
||||
int bounds = -1;
|
||||
if (!TextUtils.isEmpty(before)) {
|
||||
bounds = before.length() -1;
|
||||
while (bounds > 0 && !Character.isWhitespace(before.charAt(bounds))) {
|
||||
bounds--;
|
||||
}
|
||||
before = before.subSequence(bounds, before.length());
|
||||
}
|
||||
if (!TextUtils.isEmpty(after)) {
|
||||
bounds = 0;
|
||||
while (bounds < after.length() && !Character.isWhitespace(after.charAt(bounds))) {
|
||||
bounds++;
|
||||
}
|
||||
Log.d("getSurroundingWord", "after:"+after.toString());
|
||||
after = after.subSequence(0, bounds);
|
||||
}
|
||||
return before.toString().trim() + after.toString().trim();
|
||||
}
|
||||
|
||||
protected void showAddWord() {
|
||||
if (mKeyMode == MODE_LANG) {
|
||||
// decide if we are going to look for work to base on
|
||||
String template = mComposing.toString();
|
||||
if (template.length() == 0) {
|
||||
//get surrounding word:
|
||||
template = getSurroundingWord();
|
||||
}
|
||||
Log.d("showAddWord", "WORD: "+template);
|
||||
Intent awintent = new Intent(this, AddWordAct.class);
|
||||
awintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
awintent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
|
||||
awintent.putExtra("org.nyanya.android.traditionalt9.word", mComposing.toString());
|
||||
awintent.putExtra("org.nyanya.android.traditionalt9.word", template);
|
||||
awintent.putExtra("org.nyanya.android.traditionalt9.lang", mLang.id);
|
||||
clearState();
|
||||
currentInputConnection.setComposingText("", 0);
|
||||
|
|
@ -883,6 +915,7 @@ public class TraditionalT9 extends InputMethodService implements
|
|||
prefix = mPreviousWord;
|
||||
} else {
|
||||
if (suggestions) {
|
||||
if (mCandidateView.mSelectedIndex == -1) { mCandidateView.mSelectedIndex = 0; }
|
||||
prefix = mPreviousWord = mSuggestionStrings.get(mCandidateView.mSelectedIndex);
|
||||
} else {
|
||||
prefix = mPreviousWord;
|
||||
|
|
@ -922,7 +955,7 @@ public class TraditionalT9 extends InputMethodService implements
|
|||
}
|
||||
}
|
||||
setSuggestions(mSuggestionStrings, 0);
|
||||
} else {
|
||||
} else {
|
||||
setSuggestions(null, -1);
|
||||
setCandidatesViewShown(false);
|
||||
if (interfacehandler != null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue