Fixed some bugs and cleaned up codes
* Fixed crash on backspacing from symbol (1 key) * Hopefully fixed weird crash trying to dismiss view * Fixed long press not working for SoftKeys
This commit is contained in:
parent
38df7d4563
commit
e226f45c26
13 changed files with 1169 additions and 1092 deletions
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.nyanya.android.traditionalt9"
|
||||
android:versionCode="2"
|
||||
android:versionName="1.2" >
|
||||
android:versionCode="4"
|
||||
android:versionName="git" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="8"
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
<string name="add_word">Add word</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="add_word_blank">Blank word not added.</string>
|
||||
<string name="add_word_badchar">Cannot add word with unmappable symbol.</string>
|
||||
<string name="add_word_exist1">Word (</string>
|
||||
<string name="add_word_exist2">) already in DB.</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import android.view.Window;
|
|||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
public abstract class AbsSymDialog extends Dialog
|
||||
implements View.OnClickListener {
|
||||
public abstract class AbsSymDialog extends Dialog implements
|
||||
View.OnClickListener {
|
||||
|
||||
private TraditionalT9 parent;
|
||||
private View mainview;
|
||||
|
|
@ -21,11 +21,15 @@ public abstract class AbsSymDialog extends Dialog
|
|||
private boolean started;
|
||||
|
||||
private static final int[] buttons = {
|
||||
R.id.text_keyone, R.id.text_keytwo, R.id.text_keythree,
|
||||
R.id.text_keyfour, R.id.text_keyfive, R.id.text_keysix,
|
||||
R.id.text_keyseven, R.id.text_keyeight, R.id.text_keynine,
|
||||
R.id.text_keyzero };
|
||||
private static final int[] buttons2 = { R.id.text_keystar, R.id.text_keypound };
|
||||
R.id.text_keyone, R.id.text_keytwo,
|
||||
R.id.text_keythree, R.id.text_keyfour, R.id.text_keyfive,
|
||||
R.id.text_keysix, R.id.text_keyseven, R.id.text_keyeight,
|
||||
R.id.text_keynine, R.id.text_keyzero
|
||||
};
|
||||
private static final int[] buttons2 = {
|
||||
R.id.text_keystar,
|
||||
R.id.text_keypound
|
||||
};
|
||||
|
||||
public AbsSymDialog(Context c, View mv) {
|
||||
super(c);
|
||||
|
|
@ -131,17 +135,20 @@ public abstract class AbsSymDialog extends Dialog
|
|||
nomore = symsize - 1;
|
||||
}
|
||||
for (int buttx = 0; symbx <= stop; symbx++) {
|
||||
//Log.d("SymbolDialog - updateButtons", "buttx: " + buttx + " symbx: " + symbx);
|
||||
// Log.d("SymbolDialog - updateButtons", "buttx: " + buttx +
|
||||
// " symbx: " + symbx);
|
||||
if (symbx > nomore) {
|
||||
((TextView) mainview.findViewById(buttons[buttx])).setText("");
|
||||
} else {
|
||||
((TextView)mainview.findViewById(buttons[buttx])).setText(String.valueOf(getSymbol(symbx)));
|
||||
((TextView) mainview.findViewById(buttons[buttx]))
|
||||
.setText(String.valueOf(getSymbol(symbx)));
|
||||
}
|
||||
buttx++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean onKeyDown(int keyCode, KeyEvent event){
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (event.getRepeatCount() != 0) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -178,7 +185,8 @@ public abstract class AbsSymDialog extends Dialog
|
|||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
// Log.d("AbsSymDialog.onKeyUp", "Key: " + keyCode);
|
||||
if (started) {
|
||||
started = false;
|
||||
|
|
@ -211,7 +219,8 @@ public abstract class AbsSymDialog extends Dialog
|
|||
return true;
|
||||
default:
|
||||
// KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD).getNumber(keyCode)
|
||||
//Log.w("onKeyUp", "Unhandled Key: " + keyCode + "(" + event.toString() + ")");
|
||||
// Log.w("onKeyUp", "Unhandled Key: " + keyCode + "(" +
|
||||
// event.toString() + ")");
|
||||
}
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.nyanya.android.traditionalt9;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.app.Activity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
|
|
@ -26,7 +27,11 @@ public class AddWordAct extends Activity {
|
|||
public void addWordButton(View v) {
|
||||
EditText et = (EditText) main.findViewById(R.id.add_word_text);
|
||||
// Log.d("AddWordAct", "adding word: " + et.getText());
|
||||
if (TraditionalT9.ghettoaccess == null) {
|
||||
Log.e("AddWordAct.addWordbutton", "ghettoaccess is null? Oh no.");
|
||||
} else {
|
||||
TraditionalT9.ghettoaccess.doAddWord(et.getText().toString());
|
||||
}
|
||||
this.finish();
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +41,8 @@ public class AddWordAct extends Activity {
|
|||
this.finish();
|
||||
}
|
||||
|
||||
@Override public void onStop() {
|
||||
@Override
|
||||
public void onStop() {
|
||||
TraditionalT9.ghettoaccess.addCancel();
|
||||
super.onStop();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.nyanya.android.traditionalt9.R;
|
||||
import org.nyanya.android.traditionalt9.TraditionalT9;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
|
@ -47,6 +46,7 @@ public class CandidateView extends View {
|
|||
|
||||
/**
|
||||
* Construct a CandidateView for showing suggested words for completion.
|
||||
*
|
||||
* @param context
|
||||
* @param attrs
|
||||
*/
|
||||
|
|
@ -55,11 +55,8 @@ public class CandidateView extends View {
|
|||
mSelectionHighlight = context.getResources().getDrawable(
|
||||
android.R.drawable.list_selector_background);
|
||||
mSelectionHighlight.setState(new int[] {
|
||||
android.R.attr.state_enabled,
|
||||
android.R.attr.state_focused,
|
||||
android.R.attr.state_window_focused,
|
||||
android.R.attr.state_pressed
|
||||
});
|
||||
android.R.attr.state_enabled, android.R.attr.state_focused,
|
||||
android.R.attr.state_window_focused, android.R.attr.state_pressed });
|
||||
|
||||
Resources r = context.getResources();
|
||||
|
||||
|
|
@ -84,14 +81,6 @@ public class CandidateView extends View {
|
|||
setVerticalScrollBarEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* A connection back to the service to communicate with the text field
|
||||
* @param listener
|
||||
*/
|
||||
public void setService(TraditionalT9 listener) {
|
||||
//mService = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int computeHorizontalScrollRange() {
|
||||
return mTotalWidth;
|
||||
|
|
@ -105,24 +94,24 @@ public class CandidateView extends View {
|
|||
// not have a divider below)
|
||||
|
||||
mSelectionHighlight.getPadding(mPadding);
|
||||
final int desiredHeight = ((int)mPaint.getTextSize()) + mVerticalPadding
|
||||
+ mPadding.top + mPadding.bottom;
|
||||
final int desiredHeight = ((int) mPaint.getTextSize()) + mVerticalPadding + mPadding.top
|
||||
+ mPadding.bottom;
|
||||
|
||||
// Maximum possible width and desired height
|
||||
setMeasuredDimension(measuredWidth,
|
||||
resolveSize(desiredHeight, heightMeasureSpec));
|
||||
setMeasuredDimension(measuredWidth, resolveSize(desiredHeight, heightMeasureSpec));
|
||||
}
|
||||
|
||||
/**
|
||||
* If the canvas is null, then only touch calculations are performed to pick the target
|
||||
* candidate.
|
||||
* If the canvas is null, then only touch calculations are performed to pick
|
||||
* the target candidate.
|
||||
*/
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
mTotalWidth = 0;
|
||||
if (mSuggestions == null) return;
|
||||
if (mSuggestions == null)
|
||||
return;
|
||||
|
||||
if (mBgPadding == null) {
|
||||
mBgPadding = new Rect(0, 0, 0, 0);
|
||||
|
|
@ -145,7 +134,8 @@ public class CandidateView extends View {
|
|||
mWordX[i] = x;
|
||||
mWordWidth[i] = wordWidth;
|
||||
paint.setColor(mColorNormal);
|
||||
//if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled) {
|
||||
// if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth &&
|
||||
// !scrolled) {
|
||||
if (i == mSelectedIndex) {
|
||||
canvas.translate(x, 0);
|
||||
mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height);
|
||||
|
|
@ -153,15 +143,14 @@ public class CandidateView extends View {
|
|||
canvas.translate(-x, 0);
|
||||
paint.setFakeBoldText(true);
|
||||
paint.setColor(mColorRecommended);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
paint.setColor(mColorOther);
|
||||
}
|
||||
|
||||
canvas.drawText(suggestion, x + X_GAP, y, paint);
|
||||
paint.setColor(mColorOther);
|
||||
canvas.drawLine(x + wordWidth + 0.5f, bgPadding.top,
|
||||
x + wordWidth + 0.5f, height + 1, paint);
|
||||
canvas.drawLine(x + wordWidth + 0.5f, bgPadding.top, x + wordWidth + 0.5f, height + 1,
|
||||
paint);
|
||||
paint.setFakeBoldText(false);
|
||||
|
||||
x += wordWidth;
|
||||
|
|
@ -211,7 +200,6 @@ public class CandidateView extends View {
|
|||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
protected void scrollSuggestion(int increment) {
|
||||
if (mSuggestions != null && mSuggestions.size() > 1) {
|
||||
mSelectedIndex = mSelectedIndex + increment;
|
||||
|
|
@ -235,4 +223,3 @@ public class CandidateView extends View {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@ public class CharMap {
|
|||
aMap.put('-', 1); aMap.put('"', 1); aMap.put('\'', 1); aMap.put('@', 1);
|
||||
aMap.put('#', 1); aMap.put('$', 1); aMap.put('%', 1); aMap.put('&', 1);
|
||||
aMap.put('*', 1); aMap.put('(', 1); aMap.put(')', 1); aMap.put('1', 1);
|
||||
aMap.put(':', 1); aMap.put(';', 1); aMap.put('/', 1); aMap.put('\\', 1);
|
||||
aMap.put('+', 1); aMap.put('=', 1); aMap.put('<', 1); aMap.put('>', 1);
|
||||
aMap.put('[', 1); aMap.put(']', 1); aMap.put('{', 1); aMap.put('}', 1);
|
||||
aMap.put('^', 1); aMap.put('|', 1); aMap.put('_', 1); aMap.put('~', 1);
|
||||
aMap.put('`', 1);
|
||||
aMap.put('a', 2); aMap.put('\u00e1', 2); aMap.put('\u00e4', 2);
|
||||
aMap.put('\u00e2', 2); aMap.put('\u00e0', 2); aMap.put('\u00e5', 2);
|
||||
aMap.put('b', 2); aMap.put('c', 2); aMap.put('\u00e7', 2);
|
||||
|
|
@ -35,18 +40,15 @@ public class CharMap {
|
|||
aMap.put('9', 9); aMap.put('+', 0); aMap.put('0', 0);
|
||||
CHARTABLE = Collections.unmodifiableMap(aMap);
|
||||
}
|
||||
protected static final char[][] T9TABLE = {
|
||||
{'0', '+'}, {'.', ',', '!', '?', '-', '"', '\'', '@', '#', '$', '%', '&', '*', '(', ')', '1'},
|
||||
protected static final char[][] T9TABLE = { { '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'}
|
||||
};
|
||||
{ ' ', '\n' } };
|
||||
|
||||
protected static final int[] T9CAPSTART = {
|
||||
0, 0, 3, 3, 3, 3, 3, 4, 3, 4, 0
|
||||
};
|
||||
protected static final int[] T9CAPSTART = { 0, 0, 3, 3, 3, 3, 3, 4, 3, 4, 0 };
|
||||
|
||||
protected static int[] getSequence(String word) {
|
||||
int[] intseq = new int[word.length()];
|
||||
|
|
@ -55,7 +57,8 @@ public class CharMap {
|
|||
char c = tword.charAt(i);
|
||||
Integer z = CharMap.CHARTABLE.get(c);
|
||||
if (z == null) {
|
||||
Log.e("getSequence", "ERROR: "+ (int)c + " NOT FOUND (" + Integer.toHexString((int)c) + ")");
|
||||
Log.e("getSequence",
|
||||
"ERROR: " + (int) c + " NOT FOUND (" + Integer.toHexString((int) c) + ")");
|
||||
throw new NullPointerException();
|
||||
}
|
||||
intseq[i] = z;
|
||||
|
|
@ -70,7 +73,8 @@ public class CharMap {
|
|||
char c = tword.charAt(i);
|
||||
Integer z = CharMap.CHARTABLE.get(c);
|
||||
if (z == null) {
|
||||
Log.e("getStringSequence", "ERROR: "+ (int)c + " NOT FOUND (" + Integer.toHexString((int)c) + ")");
|
||||
Log.e("getStringSequence",
|
||||
"ERROR: " + (int) c + " NOT FOUND (" + Integer.toHexString((int) c) + ")");
|
||||
throw new NullPointerException();
|
||||
}
|
||||
seq.append(z.toString());
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ public class InterfaceHandler implements View.OnClickListener, View.OnLongClickL
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void setPressed(int keyCode, boolean pressed) {
|
||||
int id = 0;
|
||||
switch (keyCode) {
|
||||
|
|
@ -62,11 +63,15 @@ public class InterfaceHandler implements View.OnClickListener, View.OnLongClickL
|
|||
|
||||
protected void showNotFound(boolean notfound) {
|
||||
if (notfound) {
|
||||
((TextView) mainview.findViewById(R.id.left_hold_upper)).setText(R.string.main_left_notfound);
|
||||
((TextView) mainview.findViewById(R.id.left_hold_lower)).setText(R.string.main_left_insert);
|
||||
((TextView) mainview.findViewById(R.id.left_hold_upper))
|
||||
.setText(R.string.main_left_notfound);
|
||||
((TextView) mainview.findViewById(R.id.left_hold_lower))
|
||||
.setText(R.string.main_left_insert);
|
||||
} else {
|
||||
((TextView) mainview.findViewById(R.id.left_hold_upper)).setText(R.string.main_left_insert);
|
||||
((TextView) mainview.findViewById(R.id.left_hold_lower)).setText(R.string.main_left_addword);
|
||||
((TextView) mainview.findViewById(R.id.left_hold_upper))
|
||||
.setText(R.string.main_left_insert);
|
||||
((TextView) mainview.findViewById(R.id.left_hold_lower))
|
||||
.setText(R.string.main_left_addword);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +87,8 @@ public class InterfaceHandler implements View.OnClickListener, View.OnLongClickL
|
|||
}
|
||||
}
|
||||
|
||||
@Override public void onClick(View v) {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.main_left:
|
||||
if (parent.mAddingWord) {
|
||||
|
|
@ -113,13 +119,15 @@ public class InterfaceHandler implements View.OnClickListener, View.OnLongClickL
|
|||
}
|
||||
}
|
||||
|
||||
@Override public boolean onLongClick(View v) {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.main_left:
|
||||
parent.showAddWord();
|
||||
break;
|
||||
case R.id.main_right:
|
||||
((InputMethodManager) parent.getSystemService (Context.INPUT_METHOD_SERVICE)).showInputMethodPicker();
|
||||
((InputMethodManager) parent.getSystemService(Context.INPUT_METHOD_SERVICE))
|
||||
.showInputMethodPicker();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -7,18 +7,14 @@ public class SmileyDialog extends AbsSymDialog {
|
|||
|
||||
private static final String[] symbols = {
|
||||
// lol wiki http://en.wikipedia.org/wiki/List_of_emoticons
|
||||
":-)", ":)", ":o)", ":]", ":3", ":c)", ":>", "=]", "=)", ":}",
|
||||
":-D", ":D", "8-D", "8D", "X-D", "XD", "=-D", "=D", "B^D",
|
||||
">:[", ":-(", ":(", ":c", ":-<", ":<", ":-[", ":[", ":{",
|
||||
":'-(", ":'(", ":'-)", ":')", ":@", "D:<", "D:", "D8", "D;", "D=", "DX",
|
||||
"v.v", "D-':", ">:O", ":-O", ":O", ":O", "o_O", "o_0", "o.O", "8-0",
|
||||
":*", ";-)", ";)", ";-]", ";]", ";D",
|
||||
">:P", ":-P", ":P", "XP", "xp", ":-p", ":p", "=p", ":-b", ":b",
|
||||
">:\\", ">:/", ":-/", ":-.", ":/", ":\\", "=/", "=\\", ":L", "=L", ":S", ">.<",
|
||||
":|", ":-|", ":$", ":-X", ":X", ":-#", ":#", "O:-)", "0:-3", "0:3", "0:-)", "0:)",
|
||||
">:)", ">;)", ">:-)", ">_>", "<_<", "\\o/", "<3", "</3",
|
||||
"=-3", "=3",
|
||||
};
|
||||
":-)", ":)", ":o)", ":]", ":3", ":c)", ":>", "=]", "=)", ":}", ":-D", ":D", "8-D",
|
||||
"8D", "X-D", "XD", "=-D", "=D", "B^D", ">:[", ":-(", ":(", ":c", ":-<", ":<", ":-[",
|
||||
":[", ":{", ":'-(", ":'(", ":'-)", ":')", ":@", "D:<", "D:", "D8", "D;", "D=", "DX",
|
||||
"v.v", "D-':", ">:O", ":-O", ":O", ":O", "o_O", "o_0", "o.O", "8-0", ":*", ";-)", ";)",
|
||||
";-]", ";]", ";D", ">:P", ":-P", ":P", "XP", "xp", ":-p", ":p", "=p", ":-b", ":b",
|
||||
">:\\", ">:/", ":-/", ":-.", ":/", ":\\", "=/", "=\\", ":L", "=L", ":S", ">.<", ":|",
|
||||
":-|", ":$", ":-X", ":X", ":-#", ":#", "O:-)", "0:-3", "0:3", "0:-)", "0:)", ">:)",
|
||||
">;)", ">:-)", ">_>", "<_<", "\\o/", "<3", "</3", "=-3", "=3", };
|
||||
|
||||
private static final int MAX_PAGE = (int) Math.ceil(symbols.length / 10.0);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,13 +3,11 @@ package org.nyanya.android.traditionalt9;
|
|||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
|
||||
public class SymbolDialog extends AbsSymDialog {
|
||||
|
||||
private static final char[] symbols = {
|
||||
'.', ',', '!', '?', '$', '&', '%', '#', '@', '"', '\'', ':', ';', '(', ')', '/', '\\',
|
||||
'-', '+', '=', '*', '<', '>', '[', ']', '{', '}', '^', '|', '_', '~', '`'
|
||||
}; //32
|
||||
'-', '+', '=', '*', '<', '>', '[', ']', '{', '}', '^', '|', '_', '~', '`' }; // 32
|
||||
private static final int MAX_PAGE = (int) Math.ceil(symbols.length / 10.0);
|
||||
|
||||
public SymbolDialog(Context c, View mv) {
|
||||
|
|
@ -36,6 +34,4 @@ public class SymbolDialog extends AbsSymDialog {
|
|||
return MAX_PAGE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -73,7 +73,12 @@ public class T9DB {
|
|||
throw new DBException(r.getString(R.string.add_word_blank));
|
||||
}
|
||||
// get int sequence
|
||||
String seq = CharMap.getStringSequence(iword);
|
||||
String seq;
|
||||
try {
|
||||
seq = CharMap.getStringSequence(iword);
|
||||
} catch (NullPointerException e) {
|
||||
throw new DBException(r.getString(R.string.add_word_badchar));
|
||||
}
|
||||
// add int sequence into num table
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(COLUMN_SEQ, seq);
|
||||
|
|
@ -83,25 +88,66 @@ public class T9DB {
|
|||
try {
|
||||
db.insertOrThrow(WORD_TABLE_NAME, null, values);
|
||||
} catch (SQLiteConstraintException e) {
|
||||
String msg = r.getString(R.string.add_word_exist1) + iword + r.getString(R.string.add_word_exist2);
|
||||
String msg = r.getString(R.string.add_word_exist1) + iword
|
||||
+ r.getString(R.string.add_word_exist2);
|
||||
Log.w("T9DB.addWord", msg);
|
||||
throw new DBException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void incrementWord(int id) {
|
||||
db.execSQL("UPDATE " + WORD_TABLE_NAME + " SET " + COLUMN_FREQUENCY + " = " +
|
||||
COLUMN_FREQUENCY + "+ 1 WHERE " + COLUMN_ID + " = \"" + id + "\"");
|
||||
// if id's freq is greater than X we should normalise those with the same seq
|
||||
db.execSQL(
|
||||
"UPDATE " + WORD_TABLE_NAME +
|
||||
" SET " + COLUMN_FREQUENCY + " = " + COLUMN_FREQUENCY + "+ 1" +
|
||||
" WHERE " + COLUMN_ID + " = \"" + id + "\"");
|
||||
// if id's freq is greater than X we should normalise those with the
|
||||
// same seq
|
||||
}
|
||||
|
||||
public void updateWords(String is, ArrayList<String> stringList, ArrayList<Integer> intList, int capsMode){
|
||||
protected String getWord(String is) {
|
||||
String result = null;
|
||||
String q =
|
||||
"SELECT " + COLUMN_WORD + " FROM " + WORD_TABLE_NAME +
|
||||
" WHERE " + COLUMN_SEQ + "=?" +
|
||||
" ORDER BY " + COLUMN_FREQUENCY + " DESC";
|
||||
Cursor cur = db.rawQuery(q, new String[] { is });
|
||||
int hits = 0;
|
||||
if (cur.moveToFirst()) {
|
||||
result = cur.getString(0);
|
||||
}
|
||||
cur.close();
|
||||
if (result != null) {
|
||||
return result;
|
||||
} else {
|
||||
int islen = is.length();
|
||||
char c = is.charAt(islen - 1);
|
||||
c++;
|
||||
q = "SELECT " + COLUMN_WORD + " FROM " + WORD_TABLE_NAME +
|
||||
" WHERE " + COLUMN_SEQ + " >= '" + is + "1" + "' AND " + COLUMN_SEQ + " < '"
|
||||
+ is.substring(0, islen - 1) + c + "'" +
|
||||
" ORDER BY " + COLUMN_FREQUENCY + " DESC, " + COLUMN_SEQ + " ASC" +
|
||||
" LIMIT " + (MAX_RESULTS - hits);
|
||||
cur = db.rawQuery(q, null);
|
||||
|
||||
if (cur.moveToFirst()) {
|
||||
result = cur.getString(1);
|
||||
}
|
||||
if (result == null) {
|
||||
result = "";
|
||||
}
|
||||
cur.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void updateWords(String is, ArrayList<String> stringList, ArrayList<Integer> intList,
|
||||
int capsMode) {
|
||||
stringList.clear();
|
||||
intList.clear();
|
||||
// String[] sa = packInts(stringToInts(is), true);
|
||||
int islen = is.length();
|
||||
String q = "SELECT " + COLUMN_ID + ", " + COLUMN_WORD +
|
||||
" FROM " + WORD_TABLE_NAME +
|
||||
String q =
|
||||
"SELECT " + COLUMN_ID + ", " + COLUMN_WORD + " FROM " + WORD_TABLE_NAME +
|
||||
" WHERE " + COLUMN_SEQ + "=?" +
|
||||
" ORDER BY " + COLUMN_FREQUENCY + " DESC";
|
||||
Cursor cur = db.rawQuery(q, new String[] { is });
|
||||
|
|
@ -121,12 +167,14 @@ public class T9DB {
|
|||
// q = "SELECT " + COLUMN_WORD +", " + COLUMN_FREQUENCY +
|
||||
// " FROM " + WORD_TABLE_NAME +
|
||||
// " WHERE " + COLUMN_SEQ + " LIKE ?" +
|
||||
// " ORDER BY " + COLUMN_SEQ + " ASC, " + COLUMN_FREQUENCY + " DESC;";
|
||||
// " ORDER BY " + COLUMN_SEQ + " ASC, " + COLUMN_FREQUENCY +
|
||||
// " DESC;";
|
||||
// c = db.rawQuery(q, new String[] {is + "_%"});
|
||||
// above is hella slow below is gotta query fast
|
||||
q = "SELECT " + COLUMN_ID + ", " + COLUMN_WORD +
|
||||
" FROM " + WORD_TABLE_NAME +
|
||||
" WHERE " + COLUMN_SEQ + " >= '" + is + "1" + "' AND " + COLUMN_SEQ + " < '" + is.substring(0, islen-1) + c + "'" +
|
||||
" WHERE " + COLUMN_SEQ + " >= '" + is + "1" + "' AND " + COLUMN_SEQ + " < '"
|
||||
+ is.substring(0, islen - 1) + c + "'" +
|
||||
" ORDER BY " + COLUMN_FREQUENCY + " DESC, " + COLUMN_SEQ + " ASC" +
|
||||
" LIMIT " + (MAX_RESULTS - hits);
|
||||
cur = db.rawQuery(q, null);
|
||||
|
|
@ -196,9 +244,8 @@ public class T9DB {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
protected void updateWordsW(String is, ArrayList<String> stringList, ArrayList<Integer> intList,
|
||||
ArrayList<Integer> freq){
|
||||
protected void updateWordsW(String is, ArrayList<String> stringList,
|
||||
ArrayList<Integer> intList, ArrayList<Integer> freq) {
|
||||
stringList.clear();
|
||||
intList.clear();
|
||||
freq.clear();
|
||||
|
|
@ -226,12 +273,14 @@ public class T9DB {
|
|||
// q = "SELECT " + COLUMN_WORD +", " + COLUMN_FREQUENCY +
|
||||
// " FROM " + WORD_TABLE_NAME +
|
||||
// " WHERE " + COLUMN_SEQ + " LIKE ?" +
|
||||
// " ORDER BY " + COLUMN_SEQ + " ASC, " + COLUMN_FREQUENCY + " DESC;";
|
||||
// " ORDER BY " + COLUMN_SEQ + " ASC, " + COLUMN_FREQUENCY +
|
||||
// " DESC;";
|
||||
// c = db.rawQuery(q, new String[] {is + "_%"});
|
||||
// above is hella slow
|
||||
q = "SELECT " + COLUMN_ID + ", " + COLUMN_WORD + ", " + COLUMN_FREQUENCY +
|
||||
" FROM " + WORD_TABLE_NAME +
|
||||
" WHERE " + COLUMN_SEQ + " >= '" + is + "' AND " + COLUMN_SEQ + " < '" + is.substring(0, islen-1) + c + "'" +
|
||||
" WHERE " + COLUMN_SEQ + " >= '" + is + "' AND " + COLUMN_SEQ
|
||||
+ " < '" + is.substring(0, islen - 1) + c + "'" +
|
||||
" ORDER BY " + COLUMN_FREQUENCY + " DESC, " + COLUMN_SEQ + " ASC" +
|
||||
" LIMIT " + (MAX_RESULTS - hits);
|
||||
cur = db.rawQuery(q, null);
|
||||
|
|
@ -250,35 +299,6 @@ public class T9DB {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
protected static int[] stringToInts(String s){
|
||||
int[] il = new int[s.length()];
|
||||
for (int x = 0; x < s.length(); x++){
|
||||
il[x] = s.charAt(x) - 48; //lol hope this is ASCII all the time
|
||||
}
|
||||
return il;
|
||||
}
|
||||
|
||||
protected static String[] packInts(int[] intseq, boolean stringArray){
|
||||
int[] ia = packInts(intseq);
|
||||
String[] sa = {Integer.toString(ia[0]), Integer.toString(ia[1])};
|
||||
return sa;
|
||||
}
|
||||
protected static int[] packInts(int[] intseq){
|
||||
int[] ia = {0, 0};
|
||||
|
||||
for (int x = 0; x < intseq.length; x++){
|
||||
if (x < 8){
|
||||
//packing 8 ints (<10) into 32bit int ... I hope...
|
||||
ia[0] = ia[0] | (intseq[x] << x*4);
|
||||
} else {
|
||||
ia[1] = intseq[x] << (x % 8) * 4;
|
||||
}
|
||||
}
|
||||
|
||||
return ia;
|
||||
}
|
||||
|
||||
private static class DatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
DatabaseHelper(Context context) {
|
||||
|
|
@ -287,27 +307,27 @@ public class T9DB {
|
|||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL("CREATE TABLE " + WORD_TABLE_NAME + " ("
|
||||
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ COLUMN_SEQ + " TEXT, "
|
||||
+ COLUMN_WORD + " TEXT UNIQUE, "
|
||||
+ COLUMN_FREQUENCY + " INTEGER"
|
||||
+ ")");
|
||||
db.execSQL("CREATE TABLE " + WORD_TABLE_NAME + " (" +
|
||||
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||
COLUMN_SEQ + " TEXT, " +
|
||||
COLUMN_WORD + " TEXT UNIQUE, " +
|
||||
COLUMN_FREQUENCY + " INTEGER" + ")");
|
||||
db.execSQL("CREATE INDEX idx ON " + WORD_TABLE_NAME + "("
|
||||
//+ COLUMN_NUMHIGH + ", " + COLUMN_NUMLOW + ")");
|
||||
+ COLUMN_SEQ + " ASC, " + COLUMN_FREQUENCY + " DESC )");
|
||||
db.execSQL("CREATE TRIGGER " + FREQ_TRIGGER_NAME + " AFTER UPDATE ON " + WORD_TABLE_NAME
|
||||
+ " WHEN NEW." + COLUMN_FREQUENCY + " > " + FREQ_MAX
|
||||
+ " BEGIN"
|
||||
+ " UPDATE " + WORD_TABLE_NAME + " SET " + COLUMN_FREQUENCY
|
||||
+ " = " + COLUMN_FREQUENCY + " / " + FREQ_DIV + " WHERE " + COLUMN_SEQ + " = NEW." + COLUMN_SEQ + ";"
|
||||
+ " END;");
|
||||
db.execSQL("CREATE TRIGGER " + FREQ_TRIGGER_NAME +
|
||||
" AFTER UPDATE ON " + WORD_TABLE_NAME +
|
||||
" WHEN NEW." + COLUMN_FREQUENCY + " > " + FREQ_MAX +
|
||||
" BEGIN" +
|
||||
" UPDATE " + WORD_TABLE_NAME + " SET " + COLUMN_FREQUENCY + " = "
|
||||
+ COLUMN_FREQUENCY + " / " + FREQ_DIV +
|
||||
" WHERE " + COLUMN_SEQ + " = NEW." + COLUMN_SEQ + ";" +
|
||||
" END;");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
Log.w("T9DB", "Upgrading database from version " + oldVersion + " to "
|
||||
+ newVersion + ", which will destroy all old data");
|
||||
Log.w("T9DB", "Upgrading database from version " + oldVersion + " to " + newVersion
|
||||
+ ", which will destroy all old data");
|
||||
db.execSQL("DROP TABLE IF EXISTS " + WORD_TABLE_NAME);
|
||||
db.execSQL("DROP INDEX IF EXISTS idx");
|
||||
onCreate(db);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import android.inputmethodservice.InputMethodService;
|
|||
import android.inputmethodservice.KeyboardView;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
|
|
@ -26,8 +27,8 @@ import android.view.inputmethod.EditorInfo;
|
|||
import android.view.inputmethod.InputConnection;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
public class TraditionalT9 extends InputMethodService
|
||||
implements KeyboardView.OnKeyboardActionListener {
|
||||
public class TraditionalT9 extends InputMethodService implements
|
||||
KeyboardView.OnKeyboardActionListener {
|
||||
|
||||
private CandidateView mCandidateView;
|
||||
private InterfaceHandler interfacehandler = null;
|
||||
|
|
@ -39,7 +40,6 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
private ArrayList<Integer> mSuggestionInts = new ArrayList<Integer>(10);
|
||||
private ArrayList<String> mSuggestionSym = new ArrayList<String>(16);
|
||||
|
||||
|
||||
private static final int NON_EDIT = 0;
|
||||
private static final int EDITING = 1;
|
||||
private static final int EDITING_NOSHOW = 2;
|
||||
|
|
@ -67,6 +67,7 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
|
||||
final Handler t9releasehandler = new Handler();
|
||||
Runnable mt9release = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
commitReset();
|
||||
}
|
||||
|
|
@ -82,12 +83,12 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
private static final int[] MODE_CYCLE = { MODE_EN, MODE_TEXT, MODE_NUM };
|
||||
private int mKeyMode;
|
||||
|
||||
|
||||
/**
|
||||
* Main initialization of the input method component. Be sure to call
|
||||
* to super class.
|
||||
* Main initialization of the input method component. Be sure to call to
|
||||
* super class.
|
||||
*/
|
||||
@Override public void onCreate() {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
mPrevious = -1;
|
||||
|
|
@ -96,21 +97,13 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
db.init();
|
||||
|
||||
if (interfacehandler == null) {
|
||||
interfacehandler = new InterfaceHandler(
|
||||
getLayoutInflater().inflate(R.layout.mainview, null), this);
|
||||
interfacehandler = new InterfaceHandler(getLayoutInflater().inflate(R.layout.mainview,
|
||||
null), this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the point where you can do all of your UI initialization. It
|
||||
* is called after creation and any configuration change.
|
||||
*/
|
||||
// @Override public void onInitializeInterface() {
|
||||
// //maybe do some stuff
|
||||
//
|
||||
// }
|
||||
|
||||
@Override public boolean onEvaluateInputViewShown (){
|
||||
@Override
|
||||
public boolean onEvaluateInputViewShown() {
|
||||
if (mEditing == EDITING_NOSHOW) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -118,12 +111,13 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
}
|
||||
|
||||
/**
|
||||
* Called by the framework when your view for creating input needs to
|
||||
* be generated. This will be called the first time your input method
|
||||
* is displayed, and every time it needs to be re-created such as due to
|
||||
* a configuration change.
|
||||
* Called by the framework when your view for creating input needs to be
|
||||
* generated. This will be called the first time your input method is
|
||||
* displayed, and every time it needs to be re-created such as due to a
|
||||
* configuration change.
|
||||
*/
|
||||
@Override public View onCreateInputView() {
|
||||
@Override
|
||||
public View onCreateInputView() {
|
||||
updateKeyMode();
|
||||
View v = getLayoutInflater().inflate(R.layout.mainview, null);
|
||||
interfacehandler.changeView(v);
|
||||
|
|
@ -135,26 +129,28 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
return v;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called by the framework when your view for showing candidates needs to
|
||||
* be generated, like {@link #onCreateInputView}.
|
||||
* Called by the framework when your view for showing candidates needs to be
|
||||
* generated, like {@link #onCreateInputView}.
|
||||
*/
|
||||
@Override public View onCreateCandidatesView() {
|
||||
@Override
|
||||
public View onCreateCandidatesView() {
|
||||
mCandidateView = new CandidateView(this);
|
||||
mCandidateView.setService(this);
|
||||
return mCandidateView;
|
||||
}
|
||||
|
||||
protected void showSymbolPage() {
|
||||
if (mSymbolPopup == null) {
|
||||
mSymbolPopup = new SymbolDialog(this, getLayoutInflater().inflate(R.layout.symbolview, null));
|
||||
mSymbolPopup = new SymbolDialog(this, getLayoutInflater().inflate(R.layout.symbolview,
|
||||
null));
|
||||
}
|
||||
mSymbolPopup.doShow(getWindow().getWindow().getDecorView());
|
||||
}
|
||||
|
||||
protected void showSmileyPage() {
|
||||
if (mSmileyPopup == null) {
|
||||
mSmileyPopup = new SmileyDialog(this, getLayoutInflater().inflate(R.layout.symbolview, null));
|
||||
mSmileyPopup = new SmileyDialog(this, getLayoutInflater().inflate(R.layout.symbolview,
|
||||
null));
|
||||
}
|
||||
mSmileyPopup.doShow(getWindow().getWindow().getDecorView());
|
||||
}
|
||||
|
|
@ -175,8 +171,9 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
db.addWord(text);
|
||||
} catch (DBException e) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(e.getMessage())
|
||||
.setTitle(R.string.add_word).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
builder.setMessage(e.getMessage()).setTitle(R.string.add_word)
|
||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
|
@ -201,13 +198,15 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
|
||||
/**
|
||||
* This is the main point where we do our initialization of the input method
|
||||
* to begin operating on an application. At this point we have been
|
||||
* bound to the client, and are now receiving all of the detailed information
|
||||
* about the target of our edits.
|
||||
* to begin operating on an application. At this point we have been bound to
|
||||
* the client, and are now receiving all of the detailed information about
|
||||
* the target of our edits.
|
||||
*/
|
||||
@Override public void onStartInput(EditorInfo attribute, boolean restarting) {
|
||||
@Override
|
||||
public void onStartInput(EditorInfo attribute, boolean restarting) {
|
||||
super.onStartInput(attribute, restarting);
|
||||
//Log.d("onStartInput", "attribute.inputType: " + attribute.inputType + " restarting? " + restarting);
|
||||
// Log.d("onStartInput", "attribute.inputType: " + attribute.inputType +
|
||||
// " restarting? " + restarting);
|
||||
if (attribute.inputType == 0) {
|
||||
// don't do anything when not in any kind of edit field.
|
||||
// should also turn off input screen and stuff
|
||||
|
|
@ -219,7 +218,8 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
mFirstPress = true;
|
||||
mEditing = EDITING;
|
||||
// Reset our state. We want to do this even if restarting, because
|
||||
// the underlying state of the text editor could have changed in any way.
|
||||
// the underlying state of the text editor could have changed in any
|
||||
// way.
|
||||
mSuggestionStrings.clear();
|
||||
mSuggestionInts.clear();
|
||||
mSuggestionSym.clear();
|
||||
|
|
@ -237,21 +237,21 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
|
||||
// We are now going to initialize our state based on the type of
|
||||
// text being edited.
|
||||
switch (attribute.inputType & EditorInfo.TYPE_MASK_CLASS) {
|
||||
case EditorInfo.TYPE_CLASS_NUMBER:
|
||||
case EditorInfo.TYPE_CLASS_DATETIME:
|
||||
switch (attribute.inputType & InputType.TYPE_MASK_CLASS) {
|
||||
case InputType.TYPE_CLASS_NUMBER:
|
||||
case InputType.TYPE_CLASS_DATETIME:
|
||||
// Numbers and dates default to the symbols keyboard, with
|
||||
// no extra features.
|
||||
mKeyMode = MODE_NUM;
|
||||
break;
|
||||
|
||||
case EditorInfo.TYPE_CLASS_PHONE:
|
||||
case InputType.TYPE_CLASS_PHONE:
|
||||
// Phones will also default to the symbols keyboard, though
|
||||
// often you will want to have a dedicated phone keyboard.
|
||||
mKeyMode = MODE_NUM;
|
||||
break;
|
||||
|
||||
case EditorInfo.TYPE_CLASS_TEXT:
|
||||
case InputType.TYPE_CLASS_TEXT:
|
||||
// This is general text editing. We will default to the
|
||||
// normal alphabetic keyboard, and assume that we should
|
||||
// be doing predictive text (showing candidates as the
|
||||
|
|
@ -260,23 +260,23 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
|
||||
// We now look for a few special variations of text that will
|
||||
// modify our behavior.
|
||||
int variation = attribute.inputType & EditorInfo.TYPE_MASK_VARIATION;
|
||||
if (variation == EditorInfo.TYPE_TEXT_VARIATION_PASSWORD ||
|
||||
variation == EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
|
||||
int variation = attribute.inputType & InputType.TYPE_MASK_VARIATION;
|
||||
if (variation == InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
|| variation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
|
||||
// Do not display predictions / what the user is typing
|
||||
// when they are entering a password.
|
||||
mKeyMode = MODE_TEXT;
|
||||
}
|
||||
|
||||
if (variation == EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
|
||||
|| variation == EditorInfo.TYPE_TEXT_VARIATION_URI
|
||||
|| variation == EditorInfo.TYPE_TEXT_VARIATION_FILTER) {
|
||||
if (variation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
|
||||
|| variation == InputType.TYPE_TEXT_VARIATION_URI
|
||||
|| variation == InputType.TYPE_TEXT_VARIATION_FILTER) {
|
||||
// Our predictions are not useful for e-mail addresses
|
||||
// or URIs.
|
||||
mKeyMode = MODE_TEXT;
|
||||
}
|
||||
|
||||
if ((attribute.inputType & EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) {
|
||||
if ((attribute.inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) {
|
||||
// If this is an auto-complete text view, then our predictions
|
||||
// will not be shown and instead we will allow the editor
|
||||
// to supply their own. We only show the editor's
|
||||
|
|
@ -286,8 +286,9 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
mKeyMode = Integer.parseInt(pref.getString("pref_inputmode", "0"));
|
||||
}
|
||||
|
||||
//handle filter list cases... do not hijack DPAD center and make sure back's go through proper
|
||||
if ((attribute.inputType & EditorInfo.TYPE_TEXT_VARIATION_FILTER) != 0) {
|
||||
// handle filter list cases... do not hijack DPAD center and make
|
||||
// sure back's go through proper
|
||||
if ((attribute.inputType & InputType.TYPE_TEXT_VARIATION_FILTER) != 0) {
|
||||
mEditing = EDITING_NOSHOW;
|
||||
}
|
||||
|
||||
|
|
@ -303,8 +304,8 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
// keyboard with no special features.
|
||||
updateShiftKeyState(attribute);
|
||||
}
|
||||
if (attribute.privateImeOptions != null &&
|
||||
attribute.privateImeOptions.equals("org.nyanya.android.traditionalt9.addword=true")) {
|
||||
if (attribute.privateImeOptions != null
|
||||
&& attribute.privateImeOptions.equals("org.nyanya.android.traditionalt9.addword=true")) {
|
||||
mAddingWord = true;
|
||||
// mAddingSkipInput = true;
|
||||
// Log.d("onStartInput", "ADDING WORD");
|
||||
|
|
@ -328,14 +329,14 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
|
||||
updateKeyMode();
|
||||
// show Window()?
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the user is done editing a field. We can use
|
||||
* this to reset our state.
|
||||
* This is called when the user is done editing a field. We can use this to
|
||||
* reset our state.
|
||||
*/
|
||||
@Override public void onFinishInput() {
|
||||
@Override
|
||||
public void onFinishInput() {
|
||||
super.onFinishInput();
|
||||
// Log.d("onFinishInput", "When is this called?");
|
||||
if (mEditing == EDITING) {
|
||||
|
|
@ -368,29 +369,32 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
hideStatusIcon();
|
||||
}
|
||||
|
||||
@Override public void onDestroy() {
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
db.close();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
// @Override public void onStartInputView(EditorInfo attribute, boolean restarting) {
|
||||
// Log.d("onStartInputView", "attribute.inputType: " + attribute.inputType + " restarting? " + restarting);
|
||||
// @Override public void onStartInputView(EditorInfo attribute, boolean
|
||||
// restarting) {
|
||||
// Log.d("onStartInputView", "attribute.inputType: " + attribute.inputType +
|
||||
// " restarting? " + restarting);
|
||||
// //super.onStartInputView(attribute, restarting);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Deal with the editor reporting movement of its cursor.
|
||||
*/
|
||||
@Override public void onUpdateSelection(int oldSelStart, int oldSelEnd,
|
||||
int newSelStart, int newSelEnd,
|
||||
@Override
|
||||
public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd,
|
||||
int candidatesStart, int candidatesEnd) {
|
||||
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
|
||||
candidatesStart, candidatesEnd);
|
||||
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart,
|
||||
candidatesEnd);
|
||||
|
||||
// If the current selection in the text view changes, we should
|
||||
// clear whatever candidate text we have.
|
||||
if ((mComposing.length() > 0 || mComposingI.length() > 0) && (newSelStart != candidatesEnd
|
||||
|| newSelEnd != candidatesEnd)) {
|
||||
if ((mComposing.length() > 0 || mComposingI.length() > 0)
|
||||
&& (newSelStart != candidatesEnd || newSelEnd != candidatesEnd)) {
|
||||
mComposing.setLength(0);
|
||||
mComposingI.setLength(0);
|
||||
updateCandidates();
|
||||
|
|
@ -402,31 +406,27 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
}
|
||||
|
||||
/**
|
||||
* This tells us about completions that the editor has determined based
|
||||
* on the current text in it. We want to use this in fullscreen mode
|
||||
* to show the completions ourself, since the editor can not be seen
|
||||
* in that situation.
|
||||
* This tells us about completions that the editor has determined based on
|
||||
* the current text in it. We want to use this in fullscreen mode to show
|
||||
* the completions ourself, since the editor can not be seen in that
|
||||
* situation.
|
||||
*/
|
||||
@Override public void onDisplayCompletions(CompletionInfo[] completions) {
|
||||
@Override
|
||||
public void onDisplayCompletions(CompletionInfo[] completions) {
|
||||
// ??????????????
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to monitor key events being delivered to the application.
|
||||
* We get first crack at them, and can either resume them or let them
|
||||
* continue to the app.
|
||||
* Use this to monitor key events being delivered to the application. We get
|
||||
* first crack at them, and can either resume them or let them continue to
|
||||
* the app.
|
||||
*/
|
||||
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
//Log.d("onKeyDown", "Key: " + event + " repeat?: " + event.getRepeatCount() + " long-time: " + event.isLongPress());
|
||||
//Log.d("onKeyDown", "Key: " + keyCode + " repeat?: " + event.getRepeatCount());
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
// Log.d("onKeyDown", "Key: " + event + " repeat?: " +
|
||||
// event.getRepeatCount() + " long-time: " + event.isLongPress());
|
||||
if (mEditing == NON_EDIT) {
|
||||
// // catch for UI weirdness on up event thing
|
||||
// if (mButtonClose && keyCode != KeyEvent.KEYCODE_DPAD_CENTER) {
|
||||
// mButtonClose = false;
|
||||
// return false;
|
||||
// }
|
||||
//Log.d("onKeyDown", "returned false");
|
||||
//return super.onKeyDown(keyCode, event);
|
||||
return false;
|
||||
}
|
||||
mFirstPress = false;
|
||||
|
|
@ -467,6 +467,7 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
if (!isInputViewShown()) {
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
break;
|
||||
|
||||
case KeyEvent.KEYCODE_DEL:
|
||||
// Special handling of the delete key: if we currently are
|
||||
|
|
@ -479,7 +480,6 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
// break;
|
||||
}
|
||||
|
||||
|
||||
// only handle first press except for delete
|
||||
if (event.getRepeatCount() != 0) {
|
||||
return true;
|
||||
|
|
@ -491,8 +491,8 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
case KeyEvent.KEYCODE_BACK:
|
||||
// The InputMethodService already takes care of the back
|
||||
// key for us, to dismiss the input method if it is shown.
|
||||
// but we will manage it ourselves because native Android handling of
|
||||
// the input view is ... flakey at best.
|
||||
// but we will manage it ourselves because native Android handling
|
||||
// of the input view is ... flakey at best.
|
||||
// Log.d("onKeyDown", "back pres");
|
||||
if (isInputViewShown()) {
|
||||
// Log.d("inKeyDown", "input shown");
|
||||
|
|
@ -527,7 +527,8 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
return true;
|
||||
default:
|
||||
// KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD).getNumber(keyCode)
|
||||
//Log.w("onKeyDown", "Unhandled Key: " + keyCode + "(" + event.toString() + ")");
|
||||
// Log.w("onKeyDown", "Unhandled Key: " + keyCode + "(" +
|
||||
// event.toString() + ")");
|
||||
}
|
||||
Log.w("onKeyDown", "Unhandled Key: " + keyCode + "(" + event.toString() + ")");
|
||||
return super.onKeyDown(keyCode, event);
|
||||
|
|
@ -535,7 +536,8 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
|
||||
@Override
|
||||
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
|
||||
//consume since we will assume we have already handled the long press if greater than 1
|
||||
// consume since we will assume we have already handled the long press
|
||||
// if greater than 1
|
||||
if (event.getRepeatCount() != 1) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -584,7 +586,8 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
if (interfacehandler != null) {
|
||||
interfacehandler.setPressed(keyCode, false);
|
||||
}
|
||||
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showInputMethodPicker();
|
||||
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
|
||||
.showInputMethodPicker();
|
||||
// show IME
|
||||
return true;
|
||||
}
|
||||
|
|
@ -600,12 +603,14 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
}
|
||||
|
||||
/**
|
||||
* Use this to monitor key events being delivered to the application.
|
||||
* We get first crack at them, and can either resume them or let them
|
||||
* continue to the app.
|
||||
* Use this to monitor key events being delivered to the application. We get
|
||||
* first crack at them, and can either resume them or let them continue to
|
||||
* the app.
|
||||
*/
|
||||
@Override public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
//Log.d("onKeyUp", "Key: " + keyCode + " repeat?: " + event.getRepeatCount());
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
// Log.d("onKeyUp", "Key: " + keyCode + " repeat?: " +
|
||||
// event.getRepeatCount());
|
||||
if (mEditing == NON_EDIT) {
|
||||
// if (mButtonClose) {
|
||||
// //handle UI weirdness on up event
|
||||
|
|
@ -654,9 +659,11 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
if (!isInputViewShown()) {
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Log.d("onKeyUp", "Key: " + keyCode);
|
||||
//Log.d("onKeyUp", "Key: " + event + " cancelled?: " + event.isCanceled());
|
||||
// Log.d("onKeyUp", "Key: " + event + " cancelled?: " +
|
||||
// event.isCanceled());
|
||||
if (event.isCanceled()) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -679,7 +686,8 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
case KeyEvent.KEYCODE_SOFT_RIGHT:
|
||||
case KeyEvent.KEYCODE_SOFT_LEFT:
|
||||
// if (mAddingWord){
|
||||
// Log.d("onKeyUp", "key: " + keyCode + " skip: " + mAddingSkipInput);
|
||||
// Log.d("onKeyUp", "key: " + keyCode + " skip: " +
|
||||
// mAddingSkipInput);
|
||||
// if (mAddingSkipInput) {
|
||||
// //mAddingSkipInput = false;
|
||||
// return true;
|
||||
|
|
@ -720,6 +728,7 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
private void commitTyped() {
|
||||
commitTyped(getCurrentInputConnection());
|
||||
}
|
||||
|
||||
private void commitTyped(InputConnection ic) {
|
||||
if (interfacehandler != null) {
|
||||
interfacehandler.midButtonUpdate(false);
|
||||
|
|
@ -742,7 +751,7 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
// Log.d("updateShift", "CM start: " + mCapsMode);
|
||||
if (attr != null && mCapsMode != CAPS_ALL) {
|
||||
int caps = 0;
|
||||
if (attr != null && attr.inputType != EditorInfo.TYPE_NULL) {
|
||||
if (attr != null && attr.inputType != InputType.TYPE_NULL) {
|
||||
caps = getCurrentInputConnection().getCursorCapsMode(attr.inputType);
|
||||
}
|
||||
// mInputView.setShifted(mCapsLock || caps != 0);
|
||||
|
|
@ -762,39 +771,23 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
}
|
||||
|
||||
/**
|
||||
* Helper to send a key down / key up pair to the current editor.
|
||||
* NOTE: Not supposed to use this apparently. Need to use it for DEL.
|
||||
* For other things I'll have to onText
|
||||
* Helper to send a key down / key up pair to the current editor. NOTE: Not
|
||||
* supposed to use this apparently. Need to use it for DEL. For other things
|
||||
* I'll have to onText
|
||||
*/
|
||||
private void keyDownUp(int keyEventCode) {
|
||||
InputConnection ic = getCurrentInputConnection();
|
||||
KeyEvent kv = KeyEvent.changeFlags(
|
||||
new KeyEvent(KeyEvent.ACTION_DOWN, keyEventCode), KeyEvent.FLAG_SOFT_KEYBOARD);
|
||||
KeyEvent kv = KeyEvent.changeFlags(new KeyEvent(KeyEvent.ACTION_DOWN, keyEventCode),
|
||||
KeyEvent.FLAG_SOFT_KEYBOARD);
|
||||
ic.sendKeyEvent(kv);
|
||||
kv = KeyEvent.changeFlags(
|
||||
new KeyEvent(KeyEvent.ACTION_UP, keyEventCode), KeyEvent.FLAG_SOFT_KEYBOARD);
|
||||
kv = KeyEvent.changeFlags(new KeyEvent(KeyEvent.ACTION_UP, keyEventCode),
|
||||
KeyEvent.FLAG_SOFT_KEYBOARD);
|
||||
ic.sendKeyEvent(kv);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Helper to send a character to the editor as raw key events.
|
||||
// */
|
||||
// private void sendKey(int keyCode) {
|
||||
// switch (keyCode) {
|
||||
// case '\n':
|
||||
// keyDownUp(KeyEvent.KEYCODE_ENTER);
|
||||
// break;
|
||||
// default:
|
||||
// if (keyCode >= '0' && keyCode <= '9') {
|
||||
// keyDownUp(keyCode - '0' + KeyEvent.KEYCODE_0);
|
||||
// } else {
|
||||
// getCurrentInputConnection().commitText(String.valueOf((char) keyCode), 1);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Implementation of KeyboardViewListener
|
||||
@Override
|
||||
public void onKey(int keyCode, int[] keyCodes) {
|
||||
// Log.d("OnKey", "pri: " + keyCode);
|
||||
// Log.d("onKey", "START Cm: " + mCapsMode);
|
||||
|
|
@ -838,9 +831,11 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
// Log.d("onKey", "END Cm: " + mCapsMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onText(CharSequence text) {
|
||||
InputConnection ic = getCurrentInputConnection();
|
||||
if (ic == null) return;
|
||||
if (ic == null)
|
||||
return;
|
||||
ic.beginBatchEdit();
|
||||
if (mComposing.length() > 0 || mComposingI.length() > 0) {
|
||||
commitTyped(ic);
|
||||
|
|
@ -851,7 +846,8 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
}
|
||||
|
||||
/**
|
||||
* Used from interface to either close the input UI if not composing text or to accept the composing text
|
||||
* Used from interface to either close the input UI if not composing text or
|
||||
* to accept the composing text
|
||||
*/
|
||||
protected void handleMidButton() {
|
||||
if (!isInputViewShown()) {
|
||||
|
|
@ -877,9 +873,8 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
}
|
||||
|
||||
/**
|
||||
* Update the list of available candidates from the current composing
|
||||
* text. This will need to be filled in by however you are determining
|
||||
* candidates.
|
||||
* Update the list of available candidates from the current composing text.
|
||||
* This will need to be filled in by however you are determining candidates.
|
||||
*/
|
||||
private void updateCandidates() {
|
||||
if (mKeyMode == MODE_EN) {
|
||||
|
|
@ -890,25 +885,30 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
String prefix = "";
|
||||
if (!nosuggestion) {
|
||||
prefix = mSuggestionStrings.get(mCandidateView.mSelectedIndex);
|
||||
} else if (len > 1) {
|
||||
prefix = db.getWord(mComposingI.substring(0, len - 1));
|
||||
}
|
||||
mSuggestionInts.clear();
|
||||
mSuggestionStrings.clear();
|
||||
mSuggestionSym.clear();
|
||||
db.updateWords("1", mSuggestionSym, mSuggestionInts, mCapsMode);
|
||||
for (String a : mSuggestionSym) {
|
||||
if (!nosuggestion) {
|
||||
if (prefix != "") {
|
||||
mSuggestionStrings.add(prefix + a);
|
||||
} else {
|
||||
mSuggestionStrings.add(String.valueOf(a));
|
||||
mComposingI.setLength(0);
|
||||
mComposingI.append("1");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
db.updateWords(mComposingI.toString(), mSuggestionStrings, mSuggestionInts, mCapsMode);
|
||||
db.updateWords(mComposingI.toString(), mSuggestionStrings, mSuggestionInts,
|
||||
mCapsMode);
|
||||
}
|
||||
if (!mSuggestionStrings.isEmpty()) {
|
||||
mWordFound = true;
|
||||
mComposing.setLength(0);
|
||||
mComposing.append(mSuggestionStrings.get(0).substring(0, len));
|
||||
mComposing.append(mSuggestionStrings.get(0));
|
||||
if (interfacehandler != null) {
|
||||
interfacehandler.showNotFound(false);
|
||||
}
|
||||
|
|
@ -928,8 +928,7 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
interfacehandler.showNotFound(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (mKeyMode == MODE_TEXT) {
|
||||
} else if (mKeyMode == MODE_TEXT) {
|
||||
if (mComposing.length() > 0) {
|
||||
mSuggestionStrings.clear();
|
||||
char[] ca = CharMap.T9TABLE[mPrevious];
|
||||
|
|
@ -967,6 +966,7 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
// Log.d("BS", "comp: " + length + " compI: " + length2);
|
||||
mComposing.delete(length - 1, length);
|
||||
mComposingI.delete(length2 - 1, length2);
|
||||
mSuggestionStrings.clear();
|
||||
updateCandidates();
|
||||
getCurrentInputConnection().setComposingText(mComposing, 1);
|
||||
} else if (length > 0 || length2 > 0) {
|
||||
|
|
@ -974,6 +974,7 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
mComposingI.setLength(0);
|
||||
interfacehandler.midButtonUpdate(false);
|
||||
interfacehandler.showNotFound(false);
|
||||
mSuggestionStrings.clear();
|
||||
getCurrentInputConnection().commitText("", 0);
|
||||
updateCandidates();
|
||||
} else {
|
||||
|
|
@ -989,8 +990,7 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
// do my own thing here
|
||||
if (mCapsMode == CAPS_CYCLE.length - 1) {
|
||||
mCapsMode = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
mCapsMode++;
|
||||
}
|
||||
|
||||
|
|
@ -1002,8 +1002,8 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
}
|
||||
|
||||
/**
|
||||
* handle input of a character.
|
||||
* Precondition: ONLY 0-9 AND *# ARE ALLOWED
|
||||
* handle input of a character. Precondition: ONLY 0-9 AND *# ARE ALLOWED
|
||||
*
|
||||
* @param keyCode
|
||||
*/
|
||||
private void handleCharacter(int keyCode) {
|
||||
|
|
@ -1107,9 +1107,11 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
// the underlying edit box in a somewhat reliable manner.
|
||||
// (somewhat because there are a few cases where this doesn't work properly or acts strangely.)
|
||||
private boolean handleDPAD(int keyCode, KeyEvent event, boolean keyDown) {
|
||||
//Log.d("handleConsumeDPAD", "keyCode: " + keyCode + " isKeyDown: " + isKeyDown);
|
||||
// Log.d("handleConsumeDPAD", "keyCode: " + keyCode + " isKeyDown: " +
|
||||
// isKeyDown);
|
||||
if (keyDown) {
|
||||
//track key, if seeing repeat count < 0, start sending this event and previous to super
|
||||
// track key, if seeing repeat count < 0, start sending this event
|
||||
// and previous to super
|
||||
if (event.getRepeatCount() == 0) {
|
||||
// store event
|
||||
mDPADkeyEvent = event;
|
||||
|
|
@ -1126,7 +1128,8 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// if we have been sending previous down events to super, do the same for up, else process the event
|
||||
// if we have been sending previous down events to super, do the
|
||||
// same for up, else process the event
|
||||
if (mIgnoreDPADKeyUp) {
|
||||
mIgnoreDPADKeyUp = false;
|
||||
return super.onKeyUp(keyCode, event);
|
||||
|
|
@ -1152,13 +1155,15 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
handleMidButton();
|
||||
return true;
|
||||
default:
|
||||
//Send stored event to input connection then pass current event onto super
|
||||
// Send stored event to input connection then pass current
|
||||
// event onto super
|
||||
getCurrentInputConnection().sendKeyEvent(mDPADkeyEvent);
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void commitReset() {
|
||||
commitTyped(getCurrentInputConnection());
|
||||
charReset();
|
||||
|
|
@ -1169,11 +1174,13 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
updateShiftKeyState(getCurrentInputEditorInfo());
|
||||
// Log.d("commitReset", "CM post: " + mCapsMode);
|
||||
}
|
||||
|
||||
private void charReset() {
|
||||
t9releasehandler.removeCallbacks(mt9release);
|
||||
mPrevious = -1;
|
||||
mCharIndex = 0;
|
||||
}
|
||||
|
||||
private void handleClose() {
|
||||
commitTyped(getCurrentInputConnection());
|
||||
requestHideSelf(0);
|
||||
|
|
@ -1197,9 +1204,10 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
mComposingI.setLength(0);
|
||||
getCurrentInputConnection().finishComposingText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the status icon that is appropriate in current mode
|
||||
* (based on openwmm-legacy)
|
||||
* Set the status icon that is appropriate in current mode (based on
|
||||
* openwmm-legacy)
|
||||
*/
|
||||
private void updateKeyMode() {
|
||||
int icon = 0;
|
||||
|
|
@ -1248,7 +1256,6 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
showStatusIcon(icon);
|
||||
}
|
||||
|
||||
|
||||
private void pickSelectedCandidate(InputConnection ic) {
|
||||
pickSuggestionManually(-1, ic);
|
||||
}
|
||||
|
|
@ -1261,7 +1268,8 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
// we will just commit the current text.
|
||||
if (!mSuggestionStrings.isEmpty()) {
|
||||
if (index < 0) {
|
||||
//Log.d("pickSuggestMan", "picking SELECTED: " + mSuggestionStrings.get(mCandidateView.mSelectedIndex));
|
||||
// Log.d("pickSuggestMan", "picking SELECTED: " +
|
||||
// mSuggestionStrings.get(mCandidateView.mSelectedIndex));
|
||||
// get and commit selected suggestion
|
||||
ic.commitText(mSuggestionStrings.get(mCandidateView.mSelectedIndex), 1);
|
||||
if (mKeyMode == MODE_EN) {
|
||||
|
|
@ -1282,28 +1290,33 @@ implements KeyboardView.OnKeyboardActionListener {
|
|||
/**
|
||||
* Ignore this for now.
|
||||
*/
|
||||
@Override
|
||||
public void swipeRight() {
|
||||
// if (mPredictionOn) {
|
||||
// pickDefaultCandidate();
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swipeLeft() {
|
||||
handleBackspace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swipeDown() {
|
||||
handleClose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swipeUp() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPress(int primaryCode) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRelease(int primaryCode) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,8 +72,11 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
}
|
||||
|
||||
private class LoadDictTask extends AsyncTask<String, Integer, Reply> {
|
||||
/** The system calls this to perform work in a worker thread and
|
||||
* delivers it the parameters given to AsyncTask.execute() */
|
||||
/**
|
||||
* The system calls this to perform work in a worker thread and delivers
|
||||
* it the parameters given to AsyncTask.execute()
|
||||
*/
|
||||
@Override
|
||||
protected Reply doInBackground(String... mode) {
|
||||
Reply reply = new Reply();
|
||||
SQLiteDatabase db;
|
||||
|
|
@ -103,7 +106,6 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
db.setLockingEnabled(false);
|
||||
|
||||
InsertHelper wordhelp = new InsertHelper(db, T9DB.WORD_TABLE_NAME);
|
||||
|
|
@ -133,11 +135,11 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
reply.status = false;
|
||||
reply.message = "Backup file not found: " + e.getMessage();
|
||||
db.close();
|
||||
closeStream(dictstream, reply); // this is silly but it stops IDE nagging at me.
|
||||
closeStream(dictstream, reply); // this is silly but it
|
||||
// stops IDE nagging at me.
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
try {
|
||||
dictstream = getAssets().open(dictname);
|
||||
} catch (IOException e) {
|
||||
|
|
@ -183,8 +185,8 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
try {
|
||||
while (word != null) {
|
||||
if (isCancelled()) {
|
||||
// this is useless because of dumb android bug that doesn't
|
||||
// call onCancelled after this method finishes.
|
||||
// this is useless because of dumb android bug that
|
||||
// doesn't call onCancelled after this method finishes.
|
||||
reply.status = false;
|
||||
reply.message = "User cancelled.";
|
||||
break;
|
||||
|
|
@ -231,7 +233,8 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
wordhelp.bind(freqColumn, freq);
|
||||
wordhelp.execute();
|
||||
|
||||
//System.out.println("Progress: " + pos + " Last: " + last + " fsize: " + fsize);
|
||||
// System.out.println("Progress: " + pos + " Last: " + last
|
||||
// + " fsize: " + fsize);
|
||||
if ((pos - last) > 4096) {
|
||||
// Log.d("doInBackground", "line: " + linecount);
|
||||
// Log.d("doInBackground", "word: " + word);
|
||||
|
|
@ -264,40 +267,51 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
return reply;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(Integer... progress) {
|
||||
if (pd.isShowing()) {
|
||||
pd.setProgress(progress[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
// Pointless callback. Thanks android.
|
||||
}
|
||||
|
||||
/** The system calls this to perform work in the UI thread and delivers
|
||||
* the result from doInBackground() */
|
||||
/**
|
||||
* The system calls this to perform work in the UI thread and delivers
|
||||
* the result from doInBackground()
|
||||
*/
|
||||
@Override
|
||||
protected void onPostExecute(Reply result) {
|
||||
if (pd == null) {
|
||||
// Log.d("onPostExecute", "pd");
|
||||
} else {
|
||||
// Log.d("onPostExecute", "pd");
|
||||
if (pd.isShowing()) {
|
||||
pd.dismiss();
|
||||
}
|
||||
}
|
||||
if (result == null) {
|
||||
// bad thing happened
|
||||
Log.e("onPostExecute", "Bad things happen?");
|
||||
} else {
|
||||
Log.d("onPostExecute", "Result: " + result.status + " " + result.message);
|
||||
if (!result.status) {
|
||||
showErrorDialog(caller.getResources().getString(R.string.pref_restore_title), result.message);
|
||||
showErrorDialog(caller.getResources().getString(R.string.pref_restore_title),
|
||||
result.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class DumpDictTask extends AsyncTask<String, Integer, Reply> {
|
||||
/** The system calls this to perform work in a worker thread and
|
||||
* delivers it the parameters given to AsyncTask.execute() */
|
||||
/**
|
||||
* The system calls this to perform work in a worker thread and delivers
|
||||
* it the parameters given to AsyncTask.execute()
|
||||
*/
|
||||
@Override
|
||||
protected Reply doInBackground(String... ignore) {
|
||||
Reply reply = new Reply();
|
||||
SQLiteDatabase db;
|
||||
|
|
@ -306,7 +320,8 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
int current = 0;
|
||||
int pos = 0;
|
||||
int last = 0;
|
||||
File backupfile = new File(new File(Environment.getExternalStorageDirectory(), backupdir), backupname);
|
||||
File backupfile = new File(new File(Environment.getExternalStorageDirectory(),
|
||||
backupdir), backupname);
|
||||
|
||||
db.setLockingEnabled(false);
|
||||
|
||||
|
|
@ -320,7 +335,8 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
reply.status = false;
|
||||
reply.message = "Backup file error: " + e.getMessage();
|
||||
db.close();
|
||||
closeStream(dictstream, reply); // this is silly but it stops IDE nagging at me.
|
||||
closeStream(dictstream, reply); // this is silly but it stops
|
||||
// IDE nagging at me.
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
|
@ -345,15 +361,15 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
cur.close();
|
||||
|
||||
while (current < entries) {
|
||||
q = "SELECT " + T9DB.COLUMN_ID + ", " + T9DB.COLUMN_WORD + ", " + T9DB.COLUMN_FREQUENCY +
|
||||
" FROM " + T9DB.WORD_TABLE_NAME +
|
||||
" WHERE " + T9DB.COLUMN_ID + ">" + current +
|
||||
" ORDER BY " + T9DB.COLUMN_ID +
|
||||
" LIMIT " + BACKUP_Q_LIMIT;
|
||||
q = "SELECT " + T9DB.COLUMN_ID + ", " + T9DB.COLUMN_WORD + ", "
|
||||
+ T9DB.COLUMN_FREQUENCY + " FROM " + T9DB.WORD_TABLE_NAME + " WHERE "
|
||||
+ T9DB.COLUMN_ID + ">" + current + " ORDER BY " + T9DB.COLUMN_ID + " LIMIT "
|
||||
+ BACKUP_Q_LIMIT;
|
||||
cur = db.rawQuery(q, null);
|
||||
for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
|
||||
if (isCancelled()) {
|
||||
// this is useless because of dumb android bug that doesn't
|
||||
// this is useless because of dumb android bug that
|
||||
// doesn't
|
||||
// call onCancelled after this method finishes.
|
||||
reply.status = false;
|
||||
reply.message = "User cancelled.";
|
||||
|
|
@ -396,18 +412,23 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
return reply;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(Integer... progress) {
|
||||
if (pd.isShowing()) {
|
||||
pd.setProgress(progress[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
// Pointless callback. Thanks android.
|
||||
}
|
||||
|
||||
/** The system calls this to perform work in the UI thread and delivers
|
||||
* the result from doInBackground() */
|
||||
/**
|
||||
* The system calls this to perform work in the UI thread and delivers
|
||||
* the result from doInBackground()
|
||||
*/
|
||||
@Override
|
||||
protected void onPostExecute(Reply result) {
|
||||
if (pd == null) {
|
||||
// Log.d("onPostExecute", "pd");
|
||||
|
|
@ -421,15 +442,19 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
} else {
|
||||
Log.d("onPostExecute", "Result: " + result.status + " " + result.message);
|
||||
if (!result.status) {
|
||||
showErrorDialog(caller.getResources().getString(R.string.pref_backup_title), result.message);
|
||||
showErrorDialog(caller.getResources().getString(R.string.pref_backup_title),
|
||||
result.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class NukeDictTask extends AsyncTask<String, Integer, Reply> {
|
||||
/** The system calls this to perform work in a worker thread and
|
||||
* delivers it the parameters given to AsyncTask.execute() */
|
||||
/**
|
||||
* The system calls this to perform work in a worker thread and delivers
|
||||
* it the parameters given to AsyncTask.execute()
|
||||
*/
|
||||
@Override
|
||||
protected Reply doInBackground(String... ignore) {
|
||||
Reply reply = new Reply();
|
||||
Log.d("doInBakground", "Nuking dict...");
|
||||
|
|
@ -443,12 +468,16 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
return reply;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
// Pointless callback. Thanks android.
|
||||
}
|
||||
|
||||
/** The system calls this to perform work in the UI thread and delivers
|
||||
* the result from doInBackground() */
|
||||
/**
|
||||
* The system calls this to perform work in the UI thread and delivers
|
||||
* the result from doInBackground()
|
||||
*/
|
||||
@Override
|
||||
protected void onPostExecute(Reply result) {
|
||||
if (pd == null) {
|
||||
// Log.d("onPostExecute", "pd");
|
||||
|
|
@ -462,7 +491,8 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
} else {
|
||||
Log.d("onPostExecute", "Result: " + result.status + " " + result.message);
|
||||
if (!result.status) {
|
||||
showErrorDialog(caller.getResources().getString(R.string.pref_nuke_title), result.message);
|
||||
showErrorDialog(caller.getResources().getString(R.string.pref_nuke_title),
|
||||
result.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -472,7 +502,7 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.prefs);
|
||||
Preference button = (Preference)getPreferenceManager().findPreference("loaddict");
|
||||
Preference button = getPreferenceManager().findPreference("loaddict");
|
||||
if (button != null) {
|
||||
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
|
|
@ -482,7 +512,7 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
}
|
||||
});
|
||||
}
|
||||
button = (Preference)getPreferenceManager().findPreference("nukedict");
|
||||
button = getPreferenceManager().findPreference("nukedict");
|
||||
if (button != null) {
|
||||
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
|
|
@ -493,7 +523,7 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
});
|
||||
}
|
||||
|
||||
button = (Preference)getPreferenceManager().findPreference("backupdict");
|
||||
button = getPreferenceManager().findPreference("backupdict");
|
||||
if (button != null) {
|
||||
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
|
|
@ -504,7 +534,7 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
});
|
||||
}
|
||||
|
||||
button = (Preference)getPreferenceManager().findPreference("restoredict");
|
||||
button = getPreferenceManager().findPreference("restoredict");
|
||||
if (button != null) {
|
||||
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
|
|
@ -515,7 +545,7 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
});
|
||||
}
|
||||
|
||||
button = (Preference)getPreferenceManager().findPreference("querytest");
|
||||
button = getPreferenceManager().findPreference("querytest");
|
||||
if (button != null) {
|
||||
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
|
|
@ -568,14 +598,14 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
|
||||
private void nukeDict() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(R.string.pref_nuke_warn)
|
||||
.setTitle(R.string.pref_nuke_title)
|
||||
builder.setMessage(R.string.pref_nuke_warn).setTitle(R.string.pref_nuke_title)
|
||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
prenuke(R.string.pref_nukingdict);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
|
@ -598,14 +628,14 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
|
||||
saveloc = new File(saveloc, backupname);
|
||||
if (saveloc.exists()) {
|
||||
builder.setMessage(R.string.pref_backup_warn)
|
||||
.setTitle(R.string.pref_backup_title)
|
||||
builder.setMessage(R.string.pref_backup_warn).setTitle(R.string.pref_backup_title)
|
||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
predumper(R.string.pref_savingbackup);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
|
@ -625,9 +655,9 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
}
|
||||
|
||||
private void showErrorDialog(AlertDialog.Builder builder, String title, String msg) {
|
||||
builder.setMessage(msg)
|
||||
.setTitle(title)
|
||||
builder.setMessage(msg).setTitle(title)
|
||||
.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
|
@ -635,10 +665,11 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void showErrorDialogID(AlertDialog.Builder builder, int titleid, int msgid) {
|
||||
builder.setMessage(msgid)
|
||||
.setTitle(titleid)
|
||||
builder.setMessage(msgid).setTitle(titleid)
|
||||
.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
|
@ -651,18 +682,23 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
// Environment.MEDIA_MOUNTED_READ_ONLY;
|
||||
// Environment.MEDIA_MOUNTED;
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(Environment.getExternalStorageState()) ||
|
||||
Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||
if ((new File(new File(Environment.getExternalStorageDirectory(), backupdir), backupname)).exists()) {
|
||||
if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(Environment.getExternalStorageState())
|
||||
|| Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||
if ((new File(new File(Environment.getExternalStorageDirectory(), backupdir),
|
||||
backupname)).exists()) {
|
||||
Resources res = getResources();
|
||||
builder.setMessage(res.getString(R.string.pref_restore_warn, res.getString(R.string.pref_nukedict)))
|
||||
builder
|
||||
.setMessage(
|
||||
res.getString(R.string.pref_restore_warn,
|
||||
res.getString(R.string.pref_nukedict)))
|
||||
.setTitle(R.string.pref_restore_title)
|
||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
preloader(R.string.pref_loadingbackup, "backup");
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
|
@ -670,7 +706,8 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
} else {
|
||||
showErrorDialogID(builder, R.string.pref_restore_title, R.string.pref_restore_nofile);
|
||||
showErrorDialogID(builder, R.string.pref_restore_title,
|
||||
R.string.pref_restore_nofile);
|
||||
}
|
||||
} else {
|
||||
showErrorDialogID(builder, R.string.pref_restore_title, R.string.pref_restore_noext);
|
||||
|
|
@ -759,13 +796,13 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
|||
Log.d("VALUES", "...");
|
||||
size = freqs.size();
|
||||
for (int x = 0; x < size; x++) {
|
||||
Log.d("VALUES", "Word: " + words.get(x) + " id: " + ids.get(x) + " freq: " + freqs.get(x));
|
||||
Log.d("VALUES",
|
||||
"Word: " + words.get(x) + " id: " + ids.get(x) + " freq: " + freqs.get(x));
|
||||
}
|
||||
Log.d("queryTestSingle", "done.");
|
||||
tdb.close();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dint) {
|
||||
task.cancel(false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue