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"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.nyanya.android.traditionalt9"
|
package="org.nyanya.android.traditionalt9"
|
||||||
android:versionCode="2"
|
android:versionCode="4"
|
||||||
android:versionName="1.2" >
|
android:versionName="git" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="8"
|
android:minSdkVersion="8"
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
<string name="add_word">Add word</string>
|
<string name="add_word">Add word</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="add_word_blank">Blank word not added.</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_exist1">Word (</string>
|
||||||
<string name="add_word_exist2">) already in DB.</string>
|
<string name="add_word_exist2">) already in DB.</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
|
|
|
||||||
|
|
@ -8,80 +8,84 @@ import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public abstract class AbsSymDialog extends Dialog
|
public abstract class AbsSymDialog extends Dialog implements
|
||||||
implements View.OnClickListener {
|
View.OnClickListener {
|
||||||
|
|
||||||
private TraditionalT9 parent;
|
private TraditionalT9 parent;
|
||||||
private View mainview;
|
private View mainview;
|
||||||
private int pagenum = 1;
|
private int pagenum = 1;
|
||||||
private int pageoffset = (pagenum-1)*10;
|
private int pageoffset = (pagenum - 1) * 10;
|
||||||
|
|
||||||
private int MAX_PAGE;
|
private int MAX_PAGE;
|
||||||
private String title;
|
private String title;
|
||||||
private boolean started;
|
private boolean started;
|
||||||
|
|
||||||
private static final int[] buttons = {
|
private static final int[] buttons = {
|
||||||
R.id.text_keyone, R.id.text_keytwo, R.id.text_keythree,
|
R.id.text_keyone, R.id.text_keytwo,
|
||||||
R.id.text_keyfour, R.id.text_keyfive, R.id.text_keysix,
|
R.id.text_keythree, R.id.text_keyfour, R.id.text_keyfive,
|
||||||
R.id.text_keyseven, R.id.text_keyeight, R.id.text_keynine,
|
R.id.text_keysix, R.id.text_keyseven, R.id.text_keyeight,
|
||||||
R.id.text_keyzero };
|
R.id.text_keynine, R.id.text_keyzero
|
||||||
private static final int[] buttons2 = { R.id.text_keystar, R.id.text_keypound };
|
};
|
||||||
|
private static final int[] buttons2 = {
|
||||||
|
R.id.text_keystar,
|
||||||
|
R.id.text_keypound
|
||||||
|
};
|
||||||
|
|
||||||
public AbsSymDialog(Context c, View mv) {
|
public AbsSymDialog(Context c, View mv) {
|
||||||
super(c);
|
super(c);
|
||||||
parent = (TraditionalT9) c;
|
parent = (TraditionalT9) c;
|
||||||
mainview = mv;
|
mainview = mv;
|
||||||
started = true;
|
started = true;
|
||||||
setContentView(mv);
|
setContentView(mv);
|
||||||
|
|
||||||
View button;
|
View button;
|
||||||
for (int x = 0; x < buttons.length; x++){
|
for (int x = 0; x < buttons.length; x++) {
|
||||||
button = mv.findViewById(buttons[x]);
|
button = mv.findViewById(buttons[x]);
|
||||||
button.setOnClickListener(this);
|
button.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
for (int x = 0; x < buttons2.length; x++){
|
for (int x = 0; x < buttons2.length; x++) {
|
||||||
button = mv.findViewById(buttons2[x]);
|
button = mv.findViewById(buttons2[x]);
|
||||||
button.setOnClickListener(this);
|
button.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
MAX_PAGE = getMaxPage();
|
MAX_PAGE = getMaxPage();
|
||||||
title = getTitleText();
|
title = getTitleText();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
//Log.d("SymbolPopup - onClick", "click happen: " + v);
|
// Log.d("SymbolPopup - onClick", "click happen: " + v);
|
||||||
switch (v.getId()) {
|
switch (v.getId()) {
|
||||||
case R.id.text_keyone:
|
case R.id.text_keyone:
|
||||||
sendChar(pageoffset+0);
|
sendChar(pageoffset + 0);
|
||||||
break;
|
break;
|
||||||
case R.id.text_keytwo:
|
case R.id.text_keytwo:
|
||||||
sendChar(pageoffset+1);
|
sendChar(pageoffset + 1);
|
||||||
break;
|
break;
|
||||||
case R.id.text_keythree:
|
case R.id.text_keythree:
|
||||||
sendChar(pageoffset+2);
|
sendChar(pageoffset + 2);
|
||||||
break;
|
break;
|
||||||
case R.id.text_keyfour:
|
case R.id.text_keyfour:
|
||||||
sendChar(pageoffset+3);
|
sendChar(pageoffset + 3);
|
||||||
break;
|
break;
|
||||||
case R.id.text_keyfive:
|
case R.id.text_keyfive:
|
||||||
sendChar(pageoffset+4);
|
sendChar(pageoffset + 4);
|
||||||
break;
|
break;
|
||||||
case R.id.text_keysix:
|
case R.id.text_keysix:
|
||||||
sendChar(pageoffset+5);
|
sendChar(pageoffset + 5);
|
||||||
break;
|
break;
|
||||||
case R.id.text_keyseven:
|
case R.id.text_keyseven:
|
||||||
sendChar(pageoffset+6);
|
sendChar(pageoffset + 6);
|
||||||
break;
|
break;
|
||||||
case R.id.text_keyeight:
|
case R.id.text_keyeight:
|
||||||
sendChar(pageoffset+7);
|
sendChar(pageoffset + 7);
|
||||||
break;
|
break;
|
||||||
case R.id.text_keynine:
|
case R.id.text_keynine:
|
||||||
sendChar(pageoffset+8);
|
sendChar(pageoffset + 8);
|
||||||
break;
|
break;
|
||||||
case R.id.text_keyzero:
|
case R.id.text_keyzero:
|
||||||
sendChar(pageoffset+9);
|
sendChar(pageoffset + 9);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.text_keypound:
|
case R.id.text_keypound:
|
||||||
pageChange(1);
|
pageChange(1);
|
||||||
break;
|
break;
|
||||||
|
|
@ -90,65 +94,68 @@ public abstract class AbsSymDialog extends Dialog
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String getSymbol(int index);
|
protected abstract String getSymbol(int index);
|
||||||
protected abstract String getTitleText();
|
protected abstract String getTitleText();
|
||||||
protected abstract int getSymbolSize();
|
protected abstract int getSymbolSize();
|
||||||
protected abstract int getMaxPage();
|
protected abstract int getMaxPage();
|
||||||
|
|
||||||
private void sendChar(int index) {
|
private void sendChar(int index) {
|
||||||
//Log.d("SymbolDialog - sendChar", "Sending index: " + index);
|
// Log.d("SymbolDialog - sendChar", "Sending index: " + index);
|
||||||
|
|
||||||
if (index < getSymbolSize()) {
|
if (index < getSymbolSize()) {
|
||||||
parent.onText(getSymbol(index));
|
parent.onText(getSymbol(index));
|
||||||
//then close
|
// then close
|
||||||
pagenum = 1;
|
pagenum = 1;
|
||||||
pageoffset = (pagenum-1)*10;
|
pageoffset = (pagenum - 1) * 10;
|
||||||
this.dismiss();
|
this.dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pageChange(int amt) {
|
private void pageChange(int amt) {
|
||||||
pagenum = pagenum + amt;
|
pagenum = pagenum + amt;
|
||||||
if (pagenum > MAX_PAGE ) {
|
if (pagenum > MAX_PAGE) {
|
||||||
pagenum = 1;
|
pagenum = 1;
|
||||||
} else if (pagenum < 1) {
|
} else if (pagenum < 1) {
|
||||||
pagenum = MAX_PAGE;
|
pagenum = MAX_PAGE;
|
||||||
}
|
}
|
||||||
pageoffset = (pagenum-1)*10;
|
pageoffset = (pagenum - 1) * 10;
|
||||||
updateButtons();
|
updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateButtons() {
|
private void updateButtons() {
|
||||||
// set page number text
|
// set page number text
|
||||||
setTitle("Insert "+ title + "\t\tPage " + pagenum + "/" + MAX_PAGE);
|
setTitle("Insert " + title + "\t\tPage " + pagenum + "/" + MAX_PAGE);
|
||||||
// update button labels
|
// update button labels
|
||||||
int symbx = pageoffset;
|
int symbx = pageoffset;
|
||||||
int stop = symbx + 9;
|
int stop = symbx + 9;
|
||||||
int nomore = stop;
|
int nomore = stop;
|
||||||
int symsize = getSymbolSize();
|
int symsize = getSymbolSize();
|
||||||
if (nomore >= symsize-1) {
|
if (nomore >= symsize - 1) {
|
||||||
nomore = symsize-1;
|
nomore = symsize - 1;
|
||||||
}
|
}
|
||||||
for (int buttx = 0; symbx <= stop; symbx++) {
|
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) {
|
if (symbx > nomore) {
|
||||||
((TextView)mainview.findViewById(buttons[buttx])).setText("");
|
((TextView) mainview.findViewById(buttons[buttx])).setText("");
|
||||||
} else {
|
} else {
|
||||||
((TextView)mainview.findViewById(buttons[buttx])).setText(String.valueOf(getSymbol(symbx)));
|
((TextView) mainview.findViewById(buttons[buttx]))
|
||||||
|
.setText(String.valueOf(getSymbol(symbx)));
|
||||||
}
|
}
|
||||||
buttx++;
|
buttx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean onKeyDown(int keyCode, KeyEvent event){
|
@Override
|
||||||
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
if (event.getRepeatCount() != 0) {
|
if (event.getRepeatCount() != 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (started) {
|
if (started) {
|
||||||
started = false;
|
started = false;
|
||||||
}
|
}
|
||||||
//TODO: remove emulator special keys
|
// TODO: remove emulator special keys
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case 75:
|
case 75:
|
||||||
keyCode = KeyEvent.KEYCODE_POUND;
|
keyCode = KeyEvent.KEYCODE_POUND;
|
||||||
|
|
@ -156,10 +163,10 @@ public abstract class AbsSymDialog extends Dialog
|
||||||
case 74:
|
case 74:
|
||||||
keyCode = KeyEvent.KEYCODE_STAR;
|
keyCode = KeyEvent.KEYCODE_STAR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//Log.d("AbsSymDialog.onKeyDown", "bootan pres: " + keyCode);
|
// Log.d("AbsSymDialog.onKeyDown", "bootan pres: " + keyCode);
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
|
|
||||||
case KeyEvent.KEYCODE_0:
|
case KeyEvent.KEYCODE_0:
|
||||||
case KeyEvent.KEYCODE_1:
|
case KeyEvent.KEYCODE_1:
|
||||||
case KeyEvent.KEYCODE_2:
|
case KeyEvent.KEYCODE_2:
|
||||||
|
|
@ -171,20 +178,21 @@ public abstract class AbsSymDialog extends Dialog
|
||||||
case KeyEvent.KEYCODE_8:
|
case KeyEvent.KEYCODE_8:
|
||||||
case KeyEvent.KEYCODE_9:
|
case KeyEvent.KEYCODE_9:
|
||||||
case KeyEvent.KEYCODE_POUND:
|
case KeyEvent.KEYCODE_POUND:
|
||||||
case KeyEvent.KEYCODE_STAR:
|
case KeyEvent.KEYCODE_STAR:
|
||||||
event.startTracking();
|
event.startTracking();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean onKeyUp(int keyCode, KeyEvent event) {
|
@Override
|
||||||
//Log.d("AbsSymDialog.onKeyUp", "Key: " + keyCode);
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||||
|
// Log.d("AbsSymDialog.onKeyUp", "Key: " + keyCode);
|
||||||
if (started) {
|
if (started) {
|
||||||
started = false;
|
started = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//TODO: remove emulator special keys
|
// TODO: remove emulator special keys
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case 75:
|
case 75:
|
||||||
keyCode = KeyEvent.KEYCODE_POUND;
|
keyCode = KeyEvent.KEYCODE_POUND;
|
||||||
|
|
@ -194,7 +202,7 @@ public abstract class AbsSymDialog extends Dialog
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
//pass-through
|
// pass-through
|
||||||
case KeyEvent.KEYCODE_0:
|
case KeyEvent.KEYCODE_0:
|
||||||
case KeyEvent.KEYCODE_1:
|
case KeyEvent.KEYCODE_1:
|
||||||
case KeyEvent.KEYCODE_2:
|
case KeyEvent.KEYCODE_2:
|
||||||
|
|
@ -210,47 +218,48 @@ public abstract class AbsSymDialog extends Dialog
|
||||||
onKey(keyCode);
|
onKey(keyCode);
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
//KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD).getNumber(keyCode)
|
// 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);
|
return super.onKeyUp(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onKey(int keyCode) {
|
private void onKey(int keyCode) {
|
||||||
//Log.d("OnKey", "pri: " + keyCode);
|
// Log.d("OnKey", "pri: " + keyCode);
|
||||||
//Log.d("onKey", "START Cm: " + mCapsMode);
|
// Log.d("onKey", "START Cm: " + mCapsMode);
|
||||||
//HANDLE SPECIAL KEYS
|
// HANDLE SPECIAL KEYS
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case KeyEvent.KEYCODE_1:
|
case KeyEvent.KEYCODE_1:
|
||||||
sendChar(pageoffset+0);
|
sendChar(pageoffset + 0);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.KEYCODE_2:
|
case KeyEvent.KEYCODE_2:
|
||||||
sendChar(pageoffset+1);
|
sendChar(pageoffset + 1);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.KEYCODE_3:
|
case KeyEvent.KEYCODE_3:
|
||||||
sendChar(pageoffset+2);
|
sendChar(pageoffset + 2);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.KEYCODE_4:
|
case KeyEvent.KEYCODE_4:
|
||||||
sendChar(pageoffset+3);
|
sendChar(pageoffset + 3);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.KEYCODE_5:
|
case KeyEvent.KEYCODE_5:
|
||||||
sendChar(pageoffset+4);
|
sendChar(pageoffset + 4);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.KEYCODE_6:
|
case KeyEvent.KEYCODE_6:
|
||||||
sendChar(pageoffset+5);
|
sendChar(pageoffset + 5);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.KEYCODE_7:
|
case KeyEvent.KEYCODE_7:
|
||||||
sendChar(pageoffset+6);
|
sendChar(pageoffset + 6);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.KEYCODE_8:
|
case KeyEvent.KEYCODE_8:
|
||||||
sendChar(pageoffset+7);
|
sendChar(pageoffset + 7);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.KEYCODE_9:
|
case KeyEvent.KEYCODE_9:
|
||||||
sendChar(pageoffset+8);
|
sendChar(pageoffset + 8);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.KEYCODE_0:
|
case KeyEvent.KEYCODE_0:
|
||||||
sendChar(pageoffset+9);
|
sendChar(pageoffset + 9);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.KEYCODE_STAR:
|
case KeyEvent.KEYCODE_STAR:
|
||||||
pageChange(-1);
|
pageChange(-1);
|
||||||
break;
|
break;
|
||||||
|
|
@ -259,17 +268,17 @@ public abstract class AbsSymDialog extends Dialog
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doShow(View v) {
|
protected void doShow(View v) {
|
||||||
// based on http://stackoverflow.com/a/13962770
|
// based on http://stackoverflow.com/a/13962770
|
||||||
started = true;
|
started = true;
|
||||||
Window win = getWindow();
|
Window win = getWindow();
|
||||||
WindowManager.LayoutParams lp = win.getAttributes();
|
WindowManager.LayoutParams lp = win.getAttributes();
|
||||||
lp.token = v.getWindowToken();
|
lp.token = v.getWindowToken();
|
||||||
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
|
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
|
||||||
win.setAttributes(lp);
|
win.setAttributes(lp);
|
||||||
win.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
win.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
||||||
updateButtons();
|
updateButtons();
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package org.nyanya.android.traditionalt9;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
@ -9,34 +10,39 @@ import android.widget.EditText;
|
||||||
public class AddWordAct extends Activity {
|
public class AddWordAct extends Activity {
|
||||||
|
|
||||||
View main;
|
View main;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedData) {
|
protected void onCreate(Bundle savedData) {
|
||||||
super.onCreate(savedData);
|
super.onCreate(savedData);
|
||||||
View v = getLayoutInflater().inflate(R.layout.addwordview, null);
|
View v = getLayoutInflater().inflate(R.layout.addwordview, null);
|
||||||
EditText et = (EditText)v.findViewById(R.id.add_word_text);
|
EditText et = (EditText) v.findViewById(R.id.add_word_text);
|
||||||
String word = getIntent().getStringExtra("org.nyanya.android.traditionalt9.word");
|
String word = getIntent().getStringExtra("org.nyanya.android.traditionalt9.word");
|
||||||
//Log.d("AddWord", "data.get: " + word);
|
// Log.d("AddWord", "data.get: " + word);
|
||||||
et.setText(word);
|
et.setText(word);
|
||||||
et.setSelection(word.length());
|
et.setSelection(word.length());
|
||||||
setContentView(v);
|
setContentView(v);
|
||||||
main = v;
|
main = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWordButton(View v) {
|
public void addWordButton(View v) {
|
||||||
EditText et = (EditText) main.findViewById(R.id.add_word_text);
|
EditText et = (EditText) main.findViewById(R.id.add_word_text);
|
||||||
//Log.d("AddWordAct", "adding word: " + et.getText());
|
// Log.d("AddWordAct", "adding word: " + et.getText());
|
||||||
TraditionalT9.ghettoaccess.doAddWord(et.getText().toString());
|
if (TraditionalT9.ghettoaccess == null) {
|
||||||
|
Log.e("AddWordAct.addWordbutton", "ghettoaccess is null? Oh no.");
|
||||||
|
} else {
|
||||||
|
TraditionalT9.ghettoaccess.doAddWord(et.getText().toString());
|
||||||
|
}
|
||||||
this.finish();
|
this.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelButton(View v) {
|
public void cancelButton(View v) {
|
||||||
//Log.d("AddWordAct", "Cancelled...");
|
// Log.d("AddWordAct", "Cancelled...");
|
||||||
//TraditionalT9.ghettoaccess.addCancel();
|
// TraditionalT9.ghettoaccess.addCancel();
|
||||||
this.finish();
|
this.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onStop() {
|
@Override
|
||||||
|
public void onStop() {
|
||||||
TraditionalT9.ghettoaccess.addCancel();
|
TraditionalT9.ghettoaccess.addCancel();
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.nyanya.android.traditionalt9.R;
|
import org.nyanya.android.traditionalt9.R;
|
||||||
import org.nyanya.android.traditionalt9.TraditionalT9;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
|
@ -16,223 +15,211 @@ import android.view.View;
|
||||||
|
|
||||||
public class CandidateView extends View {
|
public class CandidateView extends View {
|
||||||
|
|
||||||
//private TraditionalT9 mService;
|
// private TraditionalT9 mService;
|
||||||
private List<String> mSuggestions;
|
private List<String> mSuggestions;
|
||||||
protected int mSelectedIndex;
|
protected int mSelectedIndex;
|
||||||
|
|
||||||
private Drawable mSelectionHighlight;
|
private Drawable mSelectionHighlight;
|
||||||
|
|
||||||
private Rect mBgPadding;
|
|
||||||
|
|
||||||
private static final int MAX_SUGGESTIONS = 32;
|
private Rect mBgPadding;
|
||||||
private static final int SCROLL_PIXELS = 20;
|
|
||||||
|
|
||||||
private int[] mWordWidth = new int[MAX_SUGGESTIONS];
|
|
||||||
private int[] mWordX = new int[MAX_SUGGESTIONS];
|
|
||||||
|
|
||||||
private static final int X_GAP = 10;
|
private static final int MAX_SUGGESTIONS = 32;
|
||||||
|
private static final int SCROLL_PIXELS = 20;
|
||||||
private static final List<String> EMPTY_LIST = new ArrayList<String>();
|
|
||||||
|
|
||||||
private int mColorNormal;
|
private int[] mWordWidth = new int[MAX_SUGGESTIONS];
|
||||||
private int mColorRecommended;
|
private int[] mWordX = new int[MAX_SUGGESTIONS];
|
||||||
private int mColorOther;
|
|
||||||
private int mVerticalPadding;
|
|
||||||
private Paint mPaint;
|
|
||||||
private int mTargetScrollX;
|
|
||||||
|
|
||||||
private int mTotalWidth;
|
|
||||||
|
|
||||||
Rect mPadding;
|
|
||||||
|
|
||||||
/**
|
private static final int X_GAP = 10;
|
||||||
* Construct a CandidateView for showing suggested words for completion.
|
|
||||||
* @param context
|
|
||||||
* @param attrs
|
|
||||||
*/
|
|
||||||
public CandidateView(Context context) {
|
|
||||||
super(context);
|
|
||||||
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
|
|
||||||
});
|
|
||||||
|
|
||||||
Resources r = context.getResources();
|
private static final List<String> EMPTY_LIST = new ArrayList<String>();
|
||||||
|
|
||||||
setBackgroundColor(r.getColor(R.color.candidate_background));
|
|
||||||
|
|
||||||
mColorNormal = r.getColor(R.color.candidate_normal);
|
|
||||||
mColorRecommended = r.getColor(R.color.candidate_recommended);
|
|
||||||
mColorOther = r.getColor(R.color.candidate_other);
|
|
||||||
mVerticalPadding = r.getDimensionPixelSize(R.dimen.candidate_vertical_padding);
|
|
||||||
|
|
||||||
mPaint = new Paint();
|
|
||||||
mPaint.setColor(mColorNormal);
|
|
||||||
mPaint.setAntiAlias(true);
|
|
||||||
mPaint.setTextSize(r.getDimensionPixelSize(R.dimen.candidate_font_height));
|
|
||||||
mPaint.setStrokeWidth(0);
|
|
||||||
|
|
||||||
mPadding = new Rect();
|
|
||||||
|
|
||||||
setHorizontalFadingEdgeEnabled(true);
|
|
||||||
setWillNotDraw(false);
|
|
||||||
setHorizontalScrollBarEnabled(false);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
private int mColorNormal;
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
private int mColorRecommended;
|
||||||
int measuredWidth = resolveSize(50, widthMeasureSpec);
|
private int mColorOther;
|
||||||
|
private int mVerticalPadding;
|
||||||
// Get the desired height of the icon menu view (last row of items does
|
private Paint mPaint;
|
||||||
// not have a divider below)
|
private int mTargetScrollX;
|
||||||
|
|
||||||
mSelectionHighlight.getPadding(mPadding);
|
|
||||||
final int desiredHeight = ((int)mPaint.getTextSize()) + mVerticalPadding
|
|
||||||
+ mPadding.top + mPadding.bottom;
|
|
||||||
|
|
||||||
// Maximum possible width and desired height
|
|
||||||
setMeasuredDimension(measuredWidth,
|
|
||||||
resolveSize(desiredHeight, heightMeasureSpec));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
private int mTotalWidth;
|
||||||
* 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 (mBgPadding == null) {
|
|
||||||
mBgPadding = new Rect(0, 0, 0, 0);
|
|
||||||
if (getBackground() != null) {
|
|
||||||
getBackground().getPadding(mBgPadding);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int x = 0;
|
|
||||||
final int count = mSuggestions.size();
|
|
||||||
final int height = getHeight();
|
|
||||||
final Rect bgPadding = mBgPadding;
|
|
||||||
final Paint paint = mPaint;
|
|
||||||
final int y = (int) (((height - mPaint.getTextSize()) / 2) - mPaint.ascent());
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
Rect mPadding;
|
||||||
String suggestion = mSuggestions.get(i);
|
|
||||||
float textWidth = paint.measureText(suggestion);
|
|
||||||
final int wordWidth = (int) textWidth + X_GAP * 2;
|
|
||||||
|
|
||||||
mWordX[i] = x;
|
/**
|
||||||
mWordWidth[i] = wordWidth;
|
* Construct a CandidateView for showing suggested words for completion.
|
||||||
paint.setColor(mColorNormal);
|
*
|
||||||
//if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled) {
|
* @param context
|
||||||
if (i == mSelectedIndex) {
|
* @param attrs
|
||||||
canvas.translate(x, 0);
|
*/
|
||||||
mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height);
|
public CandidateView(Context context) {
|
||||||
mSelectionHighlight.draw(canvas);
|
super(context);
|
||||||
canvas.translate(-x, 0);
|
mSelectionHighlight = context.getResources().getDrawable(
|
||||||
paint.setFakeBoldText(true);
|
android.R.drawable.list_selector_background);
|
||||||
paint.setColor(mColorRecommended);
|
mSelectionHighlight.setState(new int[] {
|
||||||
}
|
android.R.attr.state_enabled, android.R.attr.state_focused,
|
||||||
else {
|
android.R.attr.state_window_focused, android.R.attr.state_pressed });
|
||||||
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);
|
|
||||||
paint.setFakeBoldText(false);
|
|
||||||
|
|
||||||
x += wordWidth;
|
Resources r = context.getResources();
|
||||||
}
|
|
||||||
mTotalWidth = x;
|
|
||||||
if (mTargetScrollX != getScrollX()) {
|
|
||||||
scrollToTarget();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void scrollToTarget() {
|
|
||||||
int sx = getScrollX();
|
|
||||||
if (mTargetScrollX > sx) {
|
|
||||||
sx += SCROLL_PIXELS;
|
|
||||||
if (sx >= mTargetScrollX) {
|
|
||||||
sx = mTargetScrollX;
|
|
||||||
requestLayout();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sx -= SCROLL_PIXELS;
|
|
||||||
if (sx <= mTargetScrollX) {
|
|
||||||
sx = mTargetScrollX;
|
|
||||||
requestLayout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
scrollTo(sx, getScrollY());
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSuggestions(List<String> suggestions, int initialSel) {
|
|
||||||
clear();
|
|
||||||
if (suggestions != null) {
|
|
||||||
mSuggestions = suggestions;
|
|
||||||
mSelectedIndex = initialSel;
|
|
||||||
}
|
|
||||||
scrollTo(0, 0);
|
|
||||||
mTargetScrollX = 0;
|
|
||||||
// Compute the total width
|
|
||||||
//onDraw(null);
|
|
||||||
invalidate();
|
|
||||||
requestLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
setBackgroundColor(r.getColor(R.color.candidate_background));
|
||||||
mSuggestions = EMPTY_LIST;
|
|
||||||
mSelectedIndex = -1;
|
mColorNormal = r.getColor(R.color.candidate_normal);
|
||||||
invalidate();
|
mColorRecommended = r.getColor(R.color.candidate_recommended);
|
||||||
}
|
mColorOther = r.getColor(R.color.candidate_other);
|
||||||
|
mVerticalPadding = r.getDimensionPixelSize(R.dimen.candidate_vertical_padding);
|
||||||
|
|
||||||
protected void scrollSuggestion(int increment) {
|
mPaint = new Paint();
|
||||||
if (mSuggestions != null && mSuggestions.size() > 1) {
|
mPaint.setColor(mColorNormal);
|
||||||
mSelectedIndex = mSelectedIndex + increment;
|
mPaint.setAntiAlias(true);
|
||||||
if (mSelectedIndex == mSuggestions.size()) {
|
mPaint.setTextSize(r.getDimensionPixelSize(R.dimen.candidate_font_height));
|
||||||
mSelectedIndex = 0;
|
mPaint.setStrokeWidth(0);
|
||||||
} else if (mSelectedIndex < 0) {
|
|
||||||
mSelectedIndex = mSuggestions.size()-1;
|
mPadding = new Rect();
|
||||||
}
|
|
||||||
|
setHorizontalFadingEdgeEnabled(true);
|
||||||
int fullsize = getWidth();
|
setWillNotDraw(false);
|
||||||
int halfsize = fullsize/2;
|
setHorizontalScrollBarEnabled(false);
|
||||||
mTargetScrollX = mWordX[mSelectedIndex] + (mWordWidth[mSelectedIndex]/2) - halfsize;
|
setVerticalScrollBarEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int computeHorizontalScrollRange() {
|
||||||
|
return mTotalWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
int measuredWidth = resolveSize(50, widthMeasureSpec);
|
||||||
|
|
||||||
|
// Get the desired height of the icon menu view (last row of items does
|
||||||
|
// not have a divider below)
|
||||||
|
|
||||||
|
mSelectionHighlight.getPadding(mPadding);
|
||||||
|
final int desiredHeight = ((int) mPaint.getTextSize()) + mVerticalPadding + mPadding.top
|
||||||
|
+ mPadding.bottom;
|
||||||
|
|
||||||
|
// Maximum possible width and desired height
|
||||||
|
setMeasuredDimension(measuredWidth, resolveSize(desiredHeight, heightMeasureSpec));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 (mBgPadding == null) {
|
||||||
|
mBgPadding = new Rect(0, 0, 0, 0);
|
||||||
|
if (getBackground() != null) {
|
||||||
|
getBackground().getPadding(mBgPadding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int x = 0;
|
||||||
|
final int count = mSuggestions.size();
|
||||||
|
final int height = getHeight();
|
||||||
|
final Rect bgPadding = mBgPadding;
|
||||||
|
final Paint paint = mPaint;
|
||||||
|
final int y = (int) (((height - mPaint.getTextSize()) / 2) - mPaint.ascent());
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
String suggestion = mSuggestions.get(i);
|
||||||
|
float textWidth = paint.measureText(suggestion);
|
||||||
|
final int wordWidth = (int) textWidth + X_GAP * 2;
|
||||||
|
|
||||||
|
mWordX[i] = x;
|
||||||
|
mWordWidth[i] = wordWidth;
|
||||||
|
paint.setColor(mColorNormal);
|
||||||
|
// if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth &&
|
||||||
|
// !scrolled) {
|
||||||
|
if (i == mSelectedIndex) {
|
||||||
|
canvas.translate(x, 0);
|
||||||
|
mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height);
|
||||||
|
mSelectionHighlight.draw(canvas);
|
||||||
|
canvas.translate(-x, 0);
|
||||||
|
paint.setFakeBoldText(true);
|
||||||
|
paint.setColor(mColorRecommended);
|
||||||
|
} 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);
|
||||||
|
paint.setFakeBoldText(false);
|
||||||
|
|
||||||
|
x += wordWidth;
|
||||||
|
}
|
||||||
|
mTotalWidth = x;
|
||||||
|
if (mTargetScrollX != getScrollX()) {
|
||||||
|
scrollToTarget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scrollToTarget() {
|
||||||
|
int sx = getScrollX();
|
||||||
|
if (mTargetScrollX > sx) {
|
||||||
|
sx += SCROLL_PIXELS;
|
||||||
|
if (sx >= mTargetScrollX) {
|
||||||
|
sx = mTargetScrollX;
|
||||||
|
requestLayout();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sx -= SCROLL_PIXELS;
|
||||||
|
if (sx <= mTargetScrollX) {
|
||||||
|
sx = mTargetScrollX;
|
||||||
|
requestLayout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scrollTo(sx, getScrollY());
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuggestions(List<String> suggestions, int initialSel) {
|
||||||
|
clear();
|
||||||
|
if (suggestions != null) {
|
||||||
|
mSuggestions = suggestions;
|
||||||
|
mSelectedIndex = initialSel;
|
||||||
|
}
|
||||||
|
scrollTo(0, 0);
|
||||||
|
mTargetScrollX = 0;
|
||||||
|
// Compute the total width
|
||||||
|
// onDraw(null);
|
||||||
|
invalidate();
|
||||||
|
requestLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
mSuggestions = EMPTY_LIST;
|
||||||
|
mSelectedIndex = -1;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void scrollSuggestion(int increment) {
|
||||||
|
if (mSuggestions != null && mSuggestions.size() > 1) {
|
||||||
|
mSelectedIndex = mSelectedIndex + increment;
|
||||||
|
if (mSelectedIndex == mSuggestions.size()) {
|
||||||
|
mSelectedIndex = 0;
|
||||||
|
} else if (mSelectedIndex < 0) {
|
||||||
|
mSelectedIndex = mSuggestions.size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fullsize = getWidth();
|
||||||
|
int halfsize = fullsize / 2;
|
||||||
|
mTargetScrollX = mWordX[mSelectedIndex] + (mWordWidth[mSelectedIndex] / 2) - halfsize;
|
||||||
if (mTargetScrollX < 0) {
|
if (mTargetScrollX < 0) {
|
||||||
mTargetScrollX = 0;
|
mTargetScrollX = 0;
|
||||||
} else if (mTargetScrollX > (mTotalWidth - fullsize) ) {
|
} else if (mTargetScrollX > (mTotalWidth - fullsize)) {
|
||||||
mTargetScrollX = mTotalWidth - fullsize;
|
mTargetScrollX = mTotalWidth - fullsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,18 @@ import java.util.Map;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class CharMap {
|
public class CharMap {
|
||||||
protected static final Map<Character, Integer> CHARTABLE;
|
protected static final Map<Character, Integer> CHARTABLE;
|
||||||
static {
|
static {
|
||||||
Map<Character, Integer> aMap = new HashMap<Character, Integer>();
|
Map<Character, Integer> aMap = new HashMap<Character, Integer>();
|
||||||
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('$', 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', 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('a', 2); aMap.put('\u00e1', 2); aMap.put('\u00e4', 2);
|
||||||
aMap.put('\u00e2', 2); aMap.put('\u00e0', 2); aMap.put('\u00e5', 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);
|
aMap.put('b', 2); aMap.put('c', 2); aMap.put('\u00e7', 2);
|
||||||
|
|
@ -35,46 +40,45 @@ public class CharMap {
|
||||||
aMap.put('9', 9); aMap.put('+', 0); aMap.put('0', 0);
|
aMap.put('9', 9); aMap.put('+', 0); aMap.put('0', 0);
|
||||||
CHARTABLE = Collections.unmodifiableMap(aMap);
|
CHARTABLE = Collections.unmodifiableMap(aMap);
|
||||||
}
|
}
|
||||||
protected static final char[][] T9TABLE = {
|
protected static final char[][] T9TABLE = { { '0', '+' },
|
||||||
{'0', '+'}, {'.', ',', '!', '?', '-', '"', '\'', '@', '#', '$', '%', '&', '*', '(', ')', '1'},
|
{ '.', ',', '!', '?', '-', '"', '\'', '@', '#', '$', '%', '&', '*', '(', ')', '1' },
|
||||||
{'a', 'b', 'c', 'A', 'B', 'C', '2'}, {'d', 'e', 'f', 'D', 'E', 'F', '3'},
|
{ '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'},
|
{ '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'},
|
{ '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'},
|
{ '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) {
|
||||||
};
|
|
||||||
|
|
||||||
protected static int[] getSequence(String word){
|
|
||||||
int[] intseq = new int[word.length()];
|
int[] intseq = new int[word.length()];
|
||||||
String tword = word.toLowerCase(Locale.ENGLISH);
|
String tword = word.toLowerCase(Locale.ENGLISH);
|
||||||
for (int i = 0; i < word.length(); i++){
|
for (int i = 0; i < word.length(); i++) {
|
||||||
char c = tword.charAt(i);
|
char c = tword.charAt(i);
|
||||||
Integer z = CharMap.CHARTABLE.get(c);
|
Integer z = CharMap.CHARTABLE.get(c);
|
||||||
if (z == null){
|
if (z == null) {
|
||||||
Log.e("getSequence", "ERROR: "+ (int)c + " NOT FOUND (" + Integer.toHexString((int)c) + ")");
|
Log.e("getSequence",
|
||||||
throw new NullPointerException();
|
"ERROR: " + (int) c + " NOT FOUND (" + Integer.toHexString((int) c) + ")");
|
||||||
}
|
throw new NullPointerException();
|
||||||
intseq[i] = z;
|
}
|
||||||
|
intseq[i] = z;
|
||||||
}
|
}
|
||||||
return intseq;
|
return intseq;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String getStringSequence(String word){
|
protected static String getStringSequence(String word) {
|
||||||
StringBuilder seq = new StringBuilder();
|
StringBuilder seq = new StringBuilder();
|
||||||
String tword = word.toLowerCase(Locale.ENGLISH);
|
String tword = word.toLowerCase(Locale.ENGLISH);
|
||||||
for (int i = 0; i < word.length(); i++){
|
for (int i = 0; i < word.length(); i++) {
|
||||||
char c = tword.charAt(i);
|
char c = tword.charAt(i);
|
||||||
Integer z = CharMap.CHARTABLE.get(c);
|
Integer z = CharMap.CHARTABLE.get(c);
|
||||||
if (z == null){
|
if (z == null) {
|
||||||
Log.e("getStringSequence", "ERROR: "+ (int)c + " NOT FOUND (" + Integer.toHexString((int)c) + ")");
|
Log.e("getStringSequence",
|
||||||
throw new NullPointerException();
|
"ERROR: " + (int) c + " NOT FOUND (" + Integer.toHexString((int) c) + ")");
|
||||||
}
|
throw new NullPointerException();
|
||||||
seq.append(z.toString());
|
}
|
||||||
|
seq.append(z.toString());
|
||||||
}
|
}
|
||||||
return seq.toString();
|
return seq.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,20 @@ package org.nyanya.android.traditionalt9;
|
||||||
|
|
||||||
public class DBException extends Exception {
|
public class DBException extends Exception {
|
||||||
private static final long serialVersionUID = 376752656441823823L;
|
private static final long serialVersionUID = 376752656441823823L;
|
||||||
|
|
||||||
public DBException() {
|
public DBException() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DBException(String message) {
|
public DBException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DBException(String message, Throwable cause) {
|
public DBException(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DBException(Throwable cause) {
|
public DBException(Throwable cause) {
|
||||||
super(cause);
|
super(cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,27 +14,27 @@ public class InterfaceHandler implements View.OnClickListener, View.OnLongClickL
|
||||||
private static final int[] buttons = { R.id.main_left, R.id.main_right, R.id.main_mid };
|
private static final int[] buttons = { R.id.main_left, R.id.main_right, R.id.main_mid };
|
||||||
private TraditionalT9 parent;
|
private TraditionalT9 parent;
|
||||||
private View mainview;
|
private View mainview;
|
||||||
|
|
||||||
public InterfaceHandler(View mainview, TraditionalT9 iparent) {
|
public InterfaceHandler(View mainview, TraditionalT9 iparent) {
|
||||||
this.parent = iparent;
|
this.parent = iparent;
|
||||||
changeView(mainview);
|
changeView(mainview);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected View getMainview() {
|
protected View getMainview() {
|
||||||
return mainview;
|
return mainview;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void clearParent() {
|
protected void clearParent() {
|
||||||
ViewGroup vg = ((ViewGroup)mainview.getParent());
|
ViewGroup vg = ((ViewGroup) mainview.getParent());
|
||||||
if (vg != null) {
|
if (vg != null) {
|
||||||
vg.removeView(mainview);
|
vg.removeView(mainview);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void changeView(View v){
|
protected void changeView(View v) {
|
||||||
this.mainview = v;
|
this.mainview = v;
|
||||||
View button;
|
View button;
|
||||||
for (int x = 0; x < buttons.length; x++){
|
for (int x = 0; x < buttons.length; x++) {
|
||||||
button = v.findViewById(buttons[x]);
|
button = v.findViewById(buttons[x]);
|
||||||
button.setOnClickListener(this);
|
button.setOnClickListener(this);
|
||||||
if (!parent.mAddingWord) {
|
if (!parent.mAddingWord) {
|
||||||
|
|
@ -42,9 +42,10 @@ public class InterfaceHandler implements View.OnClickListener, View.OnLongClickL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected void setPressed(int keyCode, boolean pressed){
|
|
||||||
|
protected void setPressed(int keyCode, boolean pressed) {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
switch(keyCode) {
|
switch (keyCode) {
|
||||||
case KeyEvent.KEYCODE_SOFT_LEFT:
|
case KeyEvent.KEYCODE_SOFT_LEFT:
|
||||||
id = R.id.main_left;
|
id = R.id.main_left;
|
||||||
break;
|
break;
|
||||||
|
|
@ -59,51 +60,56 @@ public class InterfaceHandler implements View.OnClickListener, View.OnLongClickL
|
||||||
((View) mainview.findViewById(id)).setPressed(pressed);
|
((View) mainview.findViewById(id)).setPressed(pressed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showNotFound(boolean notfound){
|
protected void showNotFound(boolean notfound) {
|
||||||
if (notfound) {
|
if (notfound) {
|
||||||
((TextView) mainview.findViewById(R.id.left_hold_upper)).setText(R.string.main_left_notfound);
|
((TextView) mainview.findViewById(R.id.left_hold_upper))
|
||||||
((TextView) mainview.findViewById(R.id.left_hold_lower)).setText(R.string.main_left_insert);
|
.setText(R.string.main_left_notfound);
|
||||||
|
((TextView) mainview.findViewById(R.id.left_hold_lower))
|
||||||
|
.setText(R.string.main_left_insert);
|
||||||
} else {
|
} else {
|
||||||
((TextView) mainview.findViewById(R.id.left_hold_upper)).setText(R.string.main_left_insert);
|
((TextView) mainview.findViewById(R.id.left_hold_upper))
|
||||||
((TextView) mainview.findViewById(R.id.left_hold_lower)).setText(R.string.main_left_addword);
|
.setText(R.string.main_left_insert);
|
||||||
|
((TextView) mainview.findViewById(R.id.left_hold_lower))
|
||||||
|
.setText(R.string.main_left_addword);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void emulateMiddleButton() {
|
protected void emulateMiddleButton() {
|
||||||
((Button) mainview.findViewById(R.id.main_mid)).performClick();
|
((Button) mainview.findViewById(R.id.main_mid)).performClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void midButtonUpdate(boolean composing){
|
protected void midButtonUpdate(boolean composing) {
|
||||||
if (composing) {
|
if (composing) {
|
||||||
((Button) mainview.findViewById(R.id.main_mid)).setText(R.string.main_mid_commit);
|
((Button) mainview.findViewById(R.id.main_mid)).setText(R.string.main_mid_commit);
|
||||||
} else {
|
} else {
|
||||||
((Button) mainview.findViewById(R.id.main_mid)).setText(R.string.main_mid);
|
((Button) mainview.findViewById(R.id.main_mid)).setText(R.string.main_mid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onClick(View v) {
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
switch (v.getId()) {
|
switch (v.getId()) {
|
||||||
case R.id.main_left:
|
case R.id.main_left:
|
||||||
if (parent.mAddingWord) {
|
if (parent.mAddingWord) {
|
||||||
|
parent.showSymbolPage();
|
||||||
|
} else {
|
||||||
|
if (parent.mWordFound) {
|
||||||
parent.showSymbolPage();
|
parent.showSymbolPage();
|
||||||
} else {
|
} else {
|
||||||
if (parent.mWordFound) {
|
parent.showAddWord();
|
||||||
parent.showSymbolPage();
|
|
||||||
} else {
|
|
||||||
parent.showAddWord();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case R.id.main_mid:
|
break;
|
||||||
parent.handleMidButton();
|
case R.id.main_mid:
|
||||||
break;
|
parent.handleMidButton();
|
||||||
case R.id.main_right:
|
break;
|
||||||
parent.nextKeyMode();
|
case R.id.main_right:
|
||||||
break;
|
parent.nextKeyMode();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showHold(boolean show) {
|
protected void showHold(boolean show) {
|
||||||
ViewSwitcher vs = (ViewSwitcher) mainview.findViewById(R.id.main_left);
|
ViewSwitcher vs = (ViewSwitcher) mainview.findViewById(R.id.main_left);
|
||||||
if (show) {
|
if (show) {
|
||||||
|
|
@ -113,16 +119,18 @@ public class InterfaceHandler implements View.OnClickListener, View.OnLongClickL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean onLongClick(View v) {
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
switch (v.getId()) {
|
switch (v.getId()) {
|
||||||
case R.id.main_left:
|
case R.id.main_left:
|
||||||
parent.showAddWord();
|
parent.showAddWord();
|
||||||
break;
|
break;
|
||||||
case R.id.main_right:
|
case R.id.main_right:
|
||||||
((InputMethodManager) parent.getSystemService (Context.INPUT_METHOD_SERVICE)).showInputMethodPicker();
|
((InputMethodManager) parent.getSystemService(Context.INPUT_METHOD_SERVICE))
|
||||||
break;
|
.showInputMethodPicker();
|
||||||
default:
|
break;
|
||||||
return false;
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,26 +4,22 @@ import android.content.Context;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
public class SmileyDialog extends AbsSymDialog {
|
public class SmileyDialog extends AbsSymDialog {
|
||||||
|
|
||||||
private static final String[] symbols = {
|
private static final String[] symbols = {
|
||||||
//lol wiki http://en.wikipedia.org/wiki/List_of_emoticons
|
// lol wiki http://en.wikipedia.org/wiki/List_of_emoticons
|
||||||
":-)", ":)", ":o)", ":]", ":3", ":c)", ":>", "=]", "=)", ":}",
|
":-)", ":)", ":o)", ":]", ":3", ":c)", ":>", "=]", "=)", ":}", ":-D", ":D", "8-D",
|
||||||
":-D", ":D", "8-D", "8D", "X-D", "XD", "=-D", "=D", "B^D",
|
"8D", "X-D", "XD", "=-D", "=D", "B^D", ">:[", ":-(", ":(", ":c", ":-<", ":<", ":-[",
|
||||||
">:[", ":-(", ":(", ":c", ":-<", ":<", ":-[", ":[", ":{",
|
":[", ":{", ":'-(", ":'(", ":'-)", ":')", ":@", "D:<", "D:", "D8", "D;", "D=", "DX",
|
||||||
":'-(", ":'(", ":'-)", ":')", ":@", "D:<", "D:", "D8", "D;", "D=", "DX",
|
"v.v", "D-':", ">:O", ":-O", ":O", ":O", "o_O", "o_0", "o.O", "8-0", ":*", ";-)", ";)",
|
||||||
"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",
|
||||||
":*", ";-)", ";)", ";-]", ";]", ";D",
|
">:\\", ">:/", ":-/", ":-.", ":/", ":\\", "=/", "=\\", ":L", "=L", ":S", ">.<", ":|",
|
||||||
">:P", ":-P", ":P", "XP", "xp", ":-p", ":p", "=p", ":-b", ":b",
|
":-|", ":$", ":-X", ":X", ":-#", ":#", "O:-)", "0:-3", "0:3", "0:-)", "0:)", ">:)",
|
||||||
">:\\", ">:/", ":-/", ":-.", ":/", ":\\", "=/", "=\\", ":L", "=L", ":S", ">.<",
|
">;)", ">:-)", ">_>", "<_<", "\\o/", "<3", "</3", "=-3", "=3", };
|
||||||
":|", ":-|", ":$", ":-X", ":X", ":-#", ":#", "O:-)", "0:-3", "0:3", "0:-)", "0:)",
|
|
||||||
">:)", ">;)", ">:-)", ">_>", "<_<", "\\o/", "<3", "</3",
|
private static final int MAX_PAGE = (int) Math.ceil(symbols.length / 10.0);
|
||||||
"=-3", "=3",
|
|
||||||
};
|
|
||||||
|
|
||||||
private static final int MAX_PAGE = (int)Math.ceil(symbols.length / 10.0);
|
|
||||||
|
|
||||||
public SmileyDialog(Context c, View mv) {
|
public SmileyDialog(Context c, View mv) {
|
||||||
super(c, mv);
|
super(c, mv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -45,5 +41,5 @@ public class SmileyDialog extends AbsSymDialog {
|
||||||
protected int getMaxPage() {
|
protected int getMaxPage() {
|
||||||
return MAX_PAGE;
|
return MAX_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,16 @@ package org.nyanya.android.traditionalt9;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
|
||||||
public class SymbolDialog extends AbsSymDialog {
|
public class SymbolDialog extends AbsSymDialog {
|
||||||
|
|
||||||
private static final char[] symbols = {
|
private static final char[] symbols = {
|
||||||
'.', ',', '!', '?', '$', '&', '%', '#', '@', '"', '\'', ':', ';', '(', ')', '/', '\\',
|
'.', ',', '!', '?', '$', '&', '%', '#', '@', '"', '\'', ':', ';', '(', ')', '/', '\\',
|
||||||
'-', '+', '=', '*', '<', '>', '[', ']', '{', '}', '^', '|', '_', '~', '`'
|
'-', '+', '=', '*', '<', '>', '[', ']', '{', '}', '^', '|', '_', '~', '`' }; // 32
|
||||||
}; //32
|
private static final int MAX_PAGE = (int) Math.ceil(symbols.length / 10.0);
|
||||||
private static final int MAX_PAGE = (int)Math.ceil(symbols.length / 10.0);
|
|
||||||
|
|
||||||
public SymbolDialog(Context c, View mv) {
|
public SymbolDialog(Context c, View mv) {
|
||||||
super(c, mv);
|
super(c, mv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getSymbol(int index) {
|
protected String getSymbol(int index) {
|
||||||
|
|
@ -36,6 +34,4 @@ public class SymbolDialog extends AbsSymDialog {
|
||||||
return MAX_PAGE;
|
return MAX_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -20,7 +20,7 @@ public class T9DB {
|
||||||
protected static final int DATABASE_VERSION = 1;
|
protected static final int DATABASE_VERSION = 1;
|
||||||
protected static final String WORD_TABLE_NAME = "word";
|
protected static final String WORD_TABLE_NAME = "word";
|
||||||
protected static final String FREQ_TRIGGER_NAME = "freqtrigger";
|
protected static final String FREQ_TRIGGER_NAME = "freqtrigger";
|
||||||
//50k, 10k
|
// 50k, 10k
|
||||||
private static final int FREQ_MAX = 50000;
|
private static final int FREQ_MAX = 50000;
|
||||||
private static final int FREQ_DIV = 10000;
|
private static final int FREQ_DIV = 10000;
|
||||||
|
|
||||||
|
|
@ -32,34 +32,34 @@ public class T9DB {
|
||||||
|
|
||||||
private static final int MAX_RESULTS = 8;
|
private static final int MAX_RESULTS = 8;
|
||||||
|
|
||||||
private static final int CAPS_OFF = 0;
|
private static final int CAPS_OFF = 0;
|
||||||
private static final int CAPS_SINGLE = 1;
|
private static final int CAPS_SINGLE = 1;
|
||||||
private static final int CAPS_ALL = 2;
|
private static final int CAPS_ALL = 2;
|
||||||
|
|
||||||
private DatabaseHelper mOpenHelper;
|
private DatabaseHelper mOpenHelper;
|
||||||
private SQLiteDatabase db;
|
private SQLiteDatabase db;
|
||||||
|
|
||||||
private Context parent;
|
private Context parent;
|
||||||
|
|
||||||
public T9DB(Context caller) {
|
public T9DB(Context caller) {
|
||||||
//create db
|
// create db
|
||||||
parent = caller;
|
parent = caller;
|
||||||
mOpenHelper = new DatabaseHelper(caller);
|
mOpenHelper = new DatabaseHelper(caller);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SQLiteDatabase getSQLDB(Context caller) {
|
public static SQLiteDatabase getSQLDB(Context caller) {
|
||||||
return new DatabaseHelper(caller).getWritableDatabase();
|
return new DatabaseHelper(caller).getWritableDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
db = mOpenHelper.getWritableDatabase();
|
db = mOpenHelper.getWritableDatabase();
|
||||||
//mOpenHelper.onUpgrade(db, 0, DATABASE_VERSION);
|
// mOpenHelper.onUpgrade(db, 0, DATABASE_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void nuke() {
|
public void nuke() {
|
||||||
init();
|
init();
|
||||||
mOpenHelper.onUpgrade(db, 0, DATABASE_VERSION);
|
mOpenHelper.onUpgrade(db, 0, DATABASE_VERSION);
|
||||||
|
|
@ -70,43 +70,89 @@ public class T9DB {
|
||||||
public void addWord(String iword) throws DBException {
|
public void addWord(String iword) throws DBException {
|
||||||
Resources r = parent.getResources();
|
Resources r = parent.getResources();
|
||||||
if (iword.equals("")) {
|
if (iword.equals("")) {
|
||||||
throw new DBException(r.getString(R.string.add_word_blank));
|
throw new DBException(r.getString(R.string.add_word_blank));
|
||||||
}
|
}
|
||||||
//get int sequence
|
// get int sequence
|
||||||
String seq = CharMap.getStringSequence(iword);
|
String seq;
|
||||||
//add int sequence into num table
|
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();
|
ContentValues values = new ContentValues();
|
||||||
values.put(COLUMN_SEQ, seq);
|
values.put(COLUMN_SEQ, seq);
|
||||||
//add word into word
|
// add word into word
|
||||||
values.put(COLUMN_WORD, iword);
|
values.put(COLUMN_WORD, iword);
|
||||||
values.put(COLUMN_FREQUENCY, 1);
|
values.put(COLUMN_FREQUENCY, 1);
|
||||||
try {
|
try {
|
||||||
db.insertOrThrow(WORD_TABLE_NAME, null, values);
|
db.insertOrThrow(WORD_TABLE_NAME, null, values);
|
||||||
} catch (SQLiteConstraintException e) {
|
} 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);
|
Log.w("T9DB.addWord", msg);
|
||||||
throw new DBException(msg);
|
throw new DBException(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void incrementWord(int id) {
|
public void incrementWord(int id) {
|
||||||
db.execSQL("UPDATE " + WORD_TABLE_NAME + " SET " + COLUMN_FREQUENCY + " = " +
|
db.execSQL(
|
||||||
COLUMN_FREQUENCY + "+ 1 WHERE " + COLUMN_ID + " = \"" + id + "\"");
|
"UPDATE " + WORD_TABLE_NAME +
|
||||||
// if id's freq is greater than X we should normalise those with the same seq
|
" 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
|
||||||
|
}
|
||||||
|
|
||||||
|
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){
|
public void updateWords(String is, ArrayList<String> stringList, ArrayList<Integer> intList,
|
||||||
|
int capsMode) {
|
||||||
stringList.clear();
|
stringList.clear();
|
||||||
intList.clear();
|
intList.clear();
|
||||||
//String[] sa = packInts(stringToInts(is), true);
|
// String[] sa = packInts(stringToInts(is), true);
|
||||||
int islen = is.length();
|
int islen = is.length();
|
||||||
String q = "SELECT " + COLUMN_ID + ", " + COLUMN_WORD +
|
String q =
|
||||||
" FROM " + WORD_TABLE_NAME +
|
"SELECT " + COLUMN_ID + ", " + COLUMN_WORD + " FROM " + WORD_TABLE_NAME +
|
||||||
" WHERE " + COLUMN_SEQ + "=?" +
|
" WHERE " + COLUMN_SEQ + "=?" +
|
||||||
" ORDER BY " + COLUMN_FREQUENCY + " DESC";
|
" ORDER BY " + COLUMN_FREQUENCY + " DESC";
|
||||||
Cursor cur = db.rawQuery(q, new String[] {is});
|
Cursor cur = db.rawQuery(q, new String[] { is });
|
||||||
int hits = 0;
|
int hits = 0;
|
||||||
for(cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
|
for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
|
||||||
intList.add(cur.getInt(0));
|
intList.add(cur.getInt(0));
|
||||||
stringList.add(cur.getString(1));
|
stringList.add(cur.getString(1));
|
||||||
if (hits >= 15) {
|
if (hits >= 15) {
|
||||||
|
|
@ -116,22 +162,24 @@ public class T9DB {
|
||||||
}
|
}
|
||||||
cur.close();
|
cur.close();
|
||||||
if (hits < 4) {
|
if (hits < 4) {
|
||||||
char c = is.charAt(islen-1);
|
char c = is.charAt(islen - 1);
|
||||||
c++;
|
c++;
|
||||||
// q = "SELECT " + COLUMN_WORD +", " + COLUMN_FREQUENCY +
|
// q = "SELECT " + COLUMN_WORD +", " + COLUMN_FREQUENCY +
|
||||||
// " FROM " + WORD_TABLE_NAME +
|
// " FROM " + WORD_TABLE_NAME +
|
||||||
// " WHERE " + COLUMN_SEQ + " LIKE ?" +
|
// " WHERE " + COLUMN_SEQ + " LIKE ?" +
|
||||||
// " ORDER BY " + COLUMN_SEQ + " ASC, " + COLUMN_FREQUENCY + " DESC;";
|
// " ORDER BY " + COLUMN_SEQ + " ASC, " + COLUMN_FREQUENCY +
|
||||||
// c = db.rawQuery(q, new String[] {is + "_%"});
|
// " DESC;";
|
||||||
//above is hella slow below is gotta query fast
|
// c = db.rawQuery(q, new String[] {is + "_%"});
|
||||||
|
// above is hella slow below is gotta query fast
|
||||||
q = "SELECT " + COLUMN_ID + ", " + COLUMN_WORD +
|
q = "SELECT " + COLUMN_ID + ", " + COLUMN_WORD +
|
||||||
" FROM " + WORD_TABLE_NAME +
|
" 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 + " < '"
|
||||||
" ORDER BY " + COLUMN_FREQUENCY + " DESC, " + COLUMN_SEQ + " ASC" +
|
+ is.substring(0, islen - 1) + c + "'" +
|
||||||
|
" ORDER BY " + COLUMN_FREQUENCY + " DESC, " + COLUMN_SEQ + " ASC" +
|
||||||
" LIMIT " + (MAX_RESULTS - hits);
|
" LIMIT " + (MAX_RESULTS - hits);
|
||||||
cur = db.rawQuery(q, null);
|
cur = db.rawQuery(q, null);
|
||||||
|
|
||||||
for(cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
|
for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
|
||||||
intList.add(cur.getInt(0));
|
intList.add(cur.getInt(0));
|
||||||
stringList.add(cur.getString(1));
|
stringList.add(cur.getString(1));
|
||||||
if (hits >= 10) {
|
if (hits >= 10) {
|
||||||
|
|
@ -141,11 +189,11 @@ public class T9DB {
|
||||||
}
|
}
|
||||||
cur.close();
|
cur.close();
|
||||||
}
|
}
|
||||||
//Log.d("T9DB.updateWords", "pre: " + stringList);
|
// Log.d("T9DB.updateWords", "pre: " + stringList);
|
||||||
if (capsMode == CAPS_OFF) {
|
if (capsMode == CAPS_OFF) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Log.d("T9DB.updateWords", "filtering...");
|
// Log.d("T9DB.updateWords", "filtering...");
|
||||||
// filter list
|
// filter list
|
||||||
Iterator<String> iter = stringList.iterator();
|
Iterator<String> iter = stringList.iterator();
|
||||||
String word;
|
String word;
|
||||||
|
|
@ -160,25 +208,25 @@ public class T9DB {
|
||||||
if (wordtemp.equals(word)) {
|
if (wordtemp.equals(word)) {
|
||||||
index++;
|
index++;
|
||||||
continue;
|
continue;
|
||||||
} else if (stringList.contains(wordtemp)){
|
} else if (stringList.contains(wordtemp)) {
|
||||||
//remove this entry
|
// remove this entry
|
||||||
iter.remove();
|
iter.remove();
|
||||||
removed = true;
|
removed = true;
|
||||||
} else {
|
} else {
|
||||||
stringList.set(index, wordtemp);
|
stringList.set(index, wordtemp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CAPS_SINGLE:
|
case CAPS_SINGLE:
|
||||||
if (word.length() > 1) {
|
if (word.length() > 1) {
|
||||||
wordtemp = word.substring(0, 1).toUpperCase(Locale.US) + word.substring(1);
|
wordtemp = word.substring(0, 1).toUpperCase(Locale.US) + word.substring(1);
|
||||||
} else {
|
} else {
|
||||||
wordtemp = word.toUpperCase(Locale.US);
|
wordtemp = word.toUpperCase(Locale.US);
|
||||||
}
|
}
|
||||||
if (wordtemp.equals(word)) {
|
if (wordtemp.equals(word)) {
|
||||||
index++;
|
index++;
|
||||||
continue;
|
continue;
|
||||||
} else if (stringList.contains(wordtemp)){
|
} else if (stringList.contains(wordtemp)) {
|
||||||
//remove this entry
|
// remove this entry
|
||||||
iter.remove();
|
iter.remove();
|
||||||
removed = true;
|
removed = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -195,22 +243,21 @@ public class T9DB {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void updateWordsW(String is, ArrayList<String> stringList,
|
||||||
protected void updateWordsW(String is, ArrayList<String> stringList, ArrayList<Integer> intList,
|
ArrayList<Integer> intList, ArrayList<Integer> freq) {
|
||||||
ArrayList<Integer> freq){
|
|
||||||
stringList.clear();
|
stringList.clear();
|
||||||
intList.clear();
|
intList.clear();
|
||||||
freq.clear();
|
freq.clear();
|
||||||
//String[] sa = packInts(stringToInts(is), true);
|
// String[] sa = packInts(stringToInts(is), true);
|
||||||
int islen = is.length();
|
int islen = is.length();
|
||||||
String q = "SELECT " + COLUMN_ID + ", " + COLUMN_WORD + ", " + COLUMN_FREQUENCY +
|
String q = "SELECT " + COLUMN_ID + ", " + COLUMN_WORD + ", " + COLUMN_FREQUENCY +
|
||||||
" FROM " + WORD_TABLE_NAME +
|
" FROM " + WORD_TABLE_NAME +
|
||||||
" WHERE " + COLUMN_SEQ + "=?" +
|
" WHERE " + COLUMN_SEQ + "=?" +
|
||||||
" ORDER BY " + COLUMN_FREQUENCY + " DESC";
|
" ORDER BY " + COLUMN_FREQUENCY + " DESC";
|
||||||
Cursor cur = db.rawQuery(q, new String[] {is});
|
Cursor cur = db.rawQuery(q, new String[] { is });
|
||||||
int hits = 0;
|
int hits = 0;
|
||||||
for(cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
|
for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
|
||||||
intList.add(cur.getInt(0));
|
intList.add(cur.getInt(0));
|
||||||
stringList.add(cur.getString(1));
|
stringList.add(cur.getString(1));
|
||||||
freq.add(cur.getInt(2));
|
freq.add(cur.getInt(2));
|
||||||
|
|
@ -221,22 +268,24 @@ public class T9DB {
|
||||||
}
|
}
|
||||||
cur.close();
|
cur.close();
|
||||||
if (hits < 4) {
|
if (hits < 4) {
|
||||||
char c = is.charAt(islen-1);
|
char c = is.charAt(islen - 1);
|
||||||
c++;
|
c++;
|
||||||
// q = "SELECT " + COLUMN_WORD +", " + COLUMN_FREQUENCY +
|
// q = "SELECT " + COLUMN_WORD +", " + COLUMN_FREQUENCY +
|
||||||
// " FROM " + WORD_TABLE_NAME +
|
// " FROM " + WORD_TABLE_NAME +
|
||||||
// " WHERE " + COLUMN_SEQ + " LIKE ?" +
|
// " WHERE " + COLUMN_SEQ + " LIKE ?" +
|
||||||
// " ORDER BY " + COLUMN_SEQ + " ASC, " + COLUMN_FREQUENCY + " DESC;";
|
// " ORDER BY " + COLUMN_SEQ + " ASC, " + COLUMN_FREQUENCY +
|
||||||
// c = db.rawQuery(q, new String[] {is + "_%"});
|
// " DESC;";
|
||||||
//above is hella slow
|
// c = db.rawQuery(q, new String[] {is + "_%"});
|
||||||
q = "SELECT " + COLUMN_ID + ", " + COLUMN_WORD + ", " + COLUMN_FREQUENCY +
|
// above is hella slow
|
||||||
|
q = "SELECT " + COLUMN_ID + ", " + COLUMN_WORD + ", " + COLUMN_FREQUENCY +
|
||||||
" FROM " + WORD_TABLE_NAME +
|
" FROM " + WORD_TABLE_NAME +
|
||||||
" WHERE " + COLUMN_SEQ + " >= '" + is + "' AND " + COLUMN_SEQ + " < '" + is.substring(0, islen-1) + c + "'" +
|
" WHERE " + COLUMN_SEQ + " >= '" + is + "' AND " + COLUMN_SEQ
|
||||||
" ORDER BY " + COLUMN_FREQUENCY + " DESC, " + COLUMN_SEQ + " ASC" +
|
+ " < '" + is.substring(0, islen - 1) + c + "'" +
|
||||||
|
" ORDER BY " + COLUMN_FREQUENCY + " DESC, " + COLUMN_SEQ + " ASC" +
|
||||||
" LIMIT " + (MAX_RESULTS - hits);
|
" LIMIT " + (MAX_RESULTS - hits);
|
||||||
cur = db.rawQuery(q, null);
|
cur = db.rawQuery(q, null);
|
||||||
|
|
||||||
for(cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
|
for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
|
||||||
intList.add(cur.getInt(0));
|
intList.add(cur.getInt(0));
|
||||||
stringList.add(cur.getString(1));
|
stringList.add(cur.getString(1));
|
||||||
freq.add(cur.getInt(2));
|
freq.add(cur.getInt(2));
|
||||||
|
|
@ -249,35 +298,6 @@ public class T9DB {
|
||||||
}
|
}
|
||||||
return;
|
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 {
|
private static class DatabaseHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
|
|
@ -287,27 +307,27 @@ public class T9DB {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(SQLiteDatabase db) {
|
public void onCreate(SQLiteDatabase db) {
|
||||||
db.execSQL("CREATE TABLE " + WORD_TABLE_NAME + " ("
|
db.execSQL("CREATE TABLE " + WORD_TABLE_NAME + " (" +
|
||||||
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||||
+ COLUMN_SEQ + " TEXT, "
|
COLUMN_SEQ + " TEXT, " +
|
||||||
+ COLUMN_WORD + " TEXT UNIQUE, "
|
COLUMN_WORD + " TEXT UNIQUE, " +
|
||||||
+ COLUMN_FREQUENCY + " INTEGER"
|
COLUMN_FREQUENCY + " INTEGER" + ")");
|
||||||
+ ")");
|
|
||||||
db.execSQL("CREATE INDEX idx ON " + WORD_TABLE_NAME + "("
|
db.execSQL("CREATE INDEX idx ON " + WORD_TABLE_NAME + "("
|
||||||
//+ COLUMN_NUMHIGH + ", " + COLUMN_NUMLOW + ")");
|
+ COLUMN_SEQ + " ASC, " + COLUMN_FREQUENCY + " DESC )");
|
||||||
+ COLUMN_SEQ + " ASC, " + COLUMN_FREQUENCY + " DESC )");
|
db.execSQL("CREATE TRIGGER " + FREQ_TRIGGER_NAME +
|
||||||
db.execSQL("CREATE TRIGGER " + FREQ_TRIGGER_NAME + " AFTER UPDATE ON " + WORD_TABLE_NAME
|
" AFTER UPDATE ON " + WORD_TABLE_NAME +
|
||||||
+ " WHEN NEW." + COLUMN_FREQUENCY + " > " + FREQ_MAX
|
" WHEN NEW." + COLUMN_FREQUENCY + " > " + FREQ_MAX +
|
||||||
+ " BEGIN"
|
" BEGIN" +
|
||||||
+ " UPDATE " + WORD_TABLE_NAME + " SET " + COLUMN_FREQUENCY
|
" UPDATE " + WORD_TABLE_NAME + " SET " + COLUMN_FREQUENCY + " = "
|
||||||
+ " = " + COLUMN_FREQUENCY + " / " + FREQ_DIV + " WHERE " + COLUMN_SEQ + " = NEW." + COLUMN_SEQ + ";"
|
+ COLUMN_FREQUENCY + " / " + FREQ_DIV +
|
||||||
+ " END;");
|
" WHERE " + COLUMN_SEQ + " = NEW." + COLUMN_SEQ + ";" +
|
||||||
|
" END;");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
Log.w("T9DB", "Upgrading database from version " + oldVersion + " to "
|
Log.w("T9DB", "Upgrading database from version " + oldVersion + " to " + newVersion
|
||||||
+ newVersion + ", which will destroy all old data");
|
+ ", which will destroy all old data");
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + WORD_TABLE_NAME);
|
db.execSQL("DROP TABLE IF EXISTS " + WORD_TABLE_NAME);
|
||||||
db.execSQL("DROP INDEX IF EXISTS idx");
|
db.execSQL("DROP INDEX IF EXISTS idx");
|
||||||
onCreate(db);
|
onCreate(db);
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -35,29 +35,29 @@ import android.preference.PreferenceActivity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class TraditionalT9Settings extends PreferenceActivity implements
|
public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
DialogInterface.OnCancelListener {
|
DialogInterface.OnCancelListener {
|
||||||
|
|
||||||
ProgressDialog pd = null;
|
ProgressDialog pd = null;
|
||||||
AsyncTask<String, Integer, Reply> task = null;
|
AsyncTask<String, Integer, Reply> task = null;
|
||||||
final String dictname = "dict50-utf8.jet";
|
final String dictname = "dict50-utf8.jet";
|
||||||
final String backupname = "t9backup.txt";
|
final String backupname = "t9backup.txt";
|
||||||
final String backupdir = "traditionalt9";
|
final String backupdir = "traditionalt9";
|
||||||
|
|
||||||
final int BACKUP_Q_LIMIT = 1000;
|
final int BACKUP_Q_LIMIT = 1000;
|
||||||
|
|
||||||
Context caller = null;
|
Context caller = null;
|
||||||
|
|
||||||
private class Reply {
|
private class Reply {
|
||||||
public boolean status;
|
public boolean status;
|
||||||
public String message;
|
public String message;
|
||||||
|
|
||||||
protected Reply(){
|
protected Reply() {
|
||||||
this.status = true;
|
this.status = true;
|
||||||
this.message = "None";
|
this.message = "None";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void closeStream(Closeable is, Reply reply) {
|
private void closeStream(Closeable is, Reply reply) {
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -70,10 +70,13 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
reply.message = reply.message + "\n & Couldn't close stream: " + e.getMessage();
|
reply.message = reply.message + "\n & Couldn't close stream: " + e.getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LoadDictTask extends AsyncTask<String, Integer, Reply> {
|
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) {
|
protected Reply doInBackground(String... mode) {
|
||||||
Reply reply = new Reply();
|
Reply reply = new Reply();
|
||||||
SQLiteDatabase db;
|
SQLiteDatabase db;
|
||||||
|
|
@ -82,13 +85,13 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
long pos = 0;
|
long pos = 0;
|
||||||
long last = 0;
|
long last = 0;
|
||||||
File backupfile = new File(Environment.getExternalStorageDirectory(), backupdir);
|
File backupfile = new File(Environment.getExternalStorageDirectory(), backupdir);
|
||||||
|
|
||||||
if (mode[0].equals("backup")){
|
if (mode[0].equals("backup")) {
|
||||||
//using external backup
|
// using external backup
|
||||||
backupfile = new File(backupfile, backupname);
|
backupfile = new File(backupfile, backupname);
|
||||||
fsize = backupfile.length();
|
fsize = backupfile.length();
|
||||||
} else {
|
} else {
|
||||||
//using asset:
|
// using asset:
|
||||||
AssetFileDescriptor descriptor;
|
AssetFileDescriptor descriptor;
|
||||||
try {
|
try {
|
||||||
descriptor = getAssets().openFd(dictname);
|
descriptor = getAssets().openFd(dictname);
|
||||||
|
|
@ -102,12 +105,11 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
db.setLockingEnabled(false);
|
db.setLockingEnabled(false);
|
||||||
|
|
||||||
InsertHelper wordhelp = new InsertHelper(db, T9DB.WORD_TABLE_NAME);
|
InsertHelper wordhelp = new InsertHelper(db, T9DB.WORD_TABLE_NAME);
|
||||||
|
|
||||||
final int wordColumn = wordhelp.getColumnIndex(T9DB.COLUMN_WORD);
|
final int wordColumn = wordhelp.getColumnIndex(T9DB.COLUMN_WORD);
|
||||||
final int freqColumn = wordhelp.getColumnIndex(T9DB.COLUMN_FREQUENCY);
|
final int freqColumn = wordhelp.getColumnIndex(T9DB.COLUMN_FREQUENCY);
|
||||||
final int seqColumn = wordhelp.getColumnIndex(T9DB.COLUMN_SEQ);
|
final int seqColumn = wordhelp.getColumnIndex(T9DB.COLUMN_SEQ);
|
||||||
|
|
@ -125,19 +127,19 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
Log.d("doInBakground", "Adding dict...");
|
Log.d("doInBakground", "Adding dict...");
|
||||||
BufferedReader br;
|
BufferedReader br;
|
||||||
InputStream dictstream = null;
|
InputStream dictstream = null;
|
||||||
|
|
||||||
if (mode[0].equals("backup")){
|
if (mode[0].equals("backup")) {
|
||||||
try {
|
try {
|
||||||
dictstream = new FileInputStream(backupfile);
|
dictstream = new FileInputStream(backupfile);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
reply.status = false;
|
reply.status = false;
|
||||||
reply.message = "Backup file not found: " + e.getMessage();
|
reply.message = "Backup file not found: " + e.getMessage();
|
||||||
db.close();
|
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;
|
return reply;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
try {
|
try {
|
||||||
dictstream = getAssets().open(dictname);
|
dictstream = getAssets().open(dictname);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
@ -159,7 +161,7 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
closeStream(dictstream, reply);
|
closeStream(dictstream, reply);
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
String word;
|
String word;
|
||||||
String[] ws;
|
String[] ws;
|
||||||
int freq;
|
int freq;
|
||||||
|
|
@ -176,15 +178,15 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
String seq;
|
String seq;
|
||||||
int linecount = 1;
|
int linecount = 1;
|
||||||
int wordlen;
|
int wordlen;
|
||||||
|
|
||||||
long startnow, endnow;
|
long startnow, endnow;
|
||||||
startnow = SystemClock.uptimeMillis();
|
startnow = SystemClock.uptimeMillis();
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
try {
|
try {
|
||||||
while (word != null) {
|
while (word != null) {
|
||||||
if (isCancelled()) {
|
if (isCancelled()) {
|
||||||
// this is useless because of dumb android bug that doesn't
|
// this is useless because of dumb android bug that
|
||||||
// call onCancelled after this method finishes.
|
// doesn't call onCancelled after this method finishes.
|
||||||
reply.status = false;
|
reply.status = false;
|
||||||
reply.message = "User cancelled.";
|
reply.message = "User cancelled.";
|
||||||
break;
|
break;
|
||||||
|
|
@ -193,7 +195,7 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
ws = word.split(" ");
|
ws = word.split(" ");
|
||||||
word = ws[0];
|
word = ws[0];
|
||||||
try {
|
try {
|
||||||
freq = Integer.parseInt(ws[1]);
|
freq = Integer.parseInt(ws[1]);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
reply.status = false;
|
reply.status = false;
|
||||||
reply.message = "Number error.";
|
reply.message = "Number error.";
|
||||||
|
|
@ -214,7 +216,7 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
pos += wordlen;
|
pos += wordlen;
|
||||||
try{
|
try {
|
||||||
seq = CharMap.getStringSequence(word);
|
seq = CharMap.getStringSequence(word);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
reply.status = false;
|
reply.status = false;
|
||||||
|
|
@ -223,19 +225,20 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
closeStream(dictstream, reply);
|
closeStream(dictstream, reply);
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
wordhelp.prepareForReplace();
|
wordhelp.prepareForReplace();
|
||||||
wordhelp.bind(seqColumn, seq);
|
wordhelp.bind(seqColumn, seq);
|
||||||
|
|
||||||
wordhelp.bind(wordColumn, word);
|
wordhelp.bind(wordColumn, word);
|
||||||
wordhelp.bind(freqColumn, freq);
|
wordhelp.bind(freqColumn, freq);
|
||||||
wordhelp.execute();
|
wordhelp.execute();
|
||||||
|
|
||||||
//System.out.println("Progress: " + pos + " Last: " + last + " fsize: " + fsize);
|
// System.out.println("Progress: " + pos + " Last: " + last
|
||||||
|
// + " fsize: " + fsize);
|
||||||
if ((pos - last) > 4096) {
|
if ((pos - last) > 4096) {
|
||||||
// Log.d("doInBackground", "line: " + linecount);
|
// Log.d("doInBackground", "line: " + linecount);
|
||||||
// Log.d("doInBackground", "word: " + word);
|
// Log.d("doInBackground", "word: " + word);
|
||||||
publishProgress((int)((float)pos/fsize*10000));
|
publishProgress((int) ((float) pos / fsize * 10000));
|
||||||
last = pos;
|
last = pos;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
@ -257,47 +260,58 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
wordhelp.close();
|
wordhelp.close();
|
||||||
}
|
}
|
||||||
endnow = SystemClock.uptimeMillis();
|
endnow = SystemClock.uptimeMillis();
|
||||||
Log.d("TIMING", "Excution time: "+(endnow-startnow)+" ms");
|
Log.d("TIMING", "Excution time: " + (endnow - startnow) + " ms");
|
||||||
Log.d("doInBackground", "line: " + linecount);
|
Log.d("doInBackground", "line: " + linecount);
|
||||||
db.close();
|
db.close();
|
||||||
closeStream(dictstream, reply);
|
closeStream(dictstream, reply);
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void onProgressUpdate(Integer... progress) {
|
protected void onProgressUpdate(Integer... progress) {
|
||||||
if (pd.isShowing()) {
|
if (pd.isShowing()) {
|
||||||
pd.setProgress(progress[0]);
|
pd.setProgress(progress[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onCancelled() {
|
@Override
|
||||||
// Pointless callback. Thanks android.
|
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) {
|
protected void onPostExecute(Reply result) {
|
||||||
if (pd == null){
|
if (pd == null) {
|
||||||
//Log.d("onPostExecute", "pd");
|
// Log.d("onPostExecute", "pd");
|
||||||
} else {
|
} else {
|
||||||
//Log.d("onPostExecute", "pd");
|
// Log.d("onPostExecute", "pd");
|
||||||
pd.dismiss();
|
if (pd.isShowing()) {
|
||||||
|
pd.dismiss();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (result == null){
|
if (result == null) {
|
||||||
//bad thing happened
|
// bad thing happened
|
||||||
Log.e("onPostExecute", "Bad things happen?");
|
Log.e("onPostExecute", "Bad things happen?");
|
||||||
} else {
|
} else {
|
||||||
Log.d("onPostExecute", "Result: " + result.status + " " + result.message);
|
Log.d("onPostExecute", "Result: " + result.status + " " + result.message);
|
||||||
if (!result.status) {
|
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> {
|
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) {
|
protected Reply doInBackground(String... ignore) {
|
||||||
Reply reply = new Reply();
|
Reply reply = new Reply();
|
||||||
SQLiteDatabase db;
|
SQLiteDatabase db;
|
||||||
|
|
@ -306,21 +320,23 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
int current = 0;
|
int current = 0;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int last = 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);
|
db.setLockingEnabled(false);
|
||||||
|
|
||||||
Log.d("doInBakground", "Dumping dict...");
|
Log.d("doInBakground", "Dumping dict...");
|
||||||
BufferedWriter bw;
|
BufferedWriter bw;
|
||||||
OutputStream dictstream = null;
|
OutputStream dictstream = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dictstream = new FileOutputStream(backupfile);
|
dictstream = new FileOutputStream(backupfile);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
reply.status = false;
|
reply.status = false;
|
||||||
reply.message = "Backup file error: " + e.getMessage();
|
reply.message = "Backup file error: " + e.getMessage();
|
||||||
db.close();
|
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;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -336,24 +352,24 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
}
|
}
|
||||||
long startnow, endnow;
|
long startnow, endnow;
|
||||||
startnow = SystemClock.uptimeMillis();
|
startnow = SystemClock.uptimeMillis();
|
||||||
|
|
||||||
String q = "SELECT count(*) FROM " + T9DB.WORD_TABLE_NAME;
|
String q = "SELECT count(*) FROM " + T9DB.WORD_TABLE_NAME;
|
||||||
Cursor cur = db.rawQuery(q, null);
|
Cursor cur = db.rawQuery(q, null);
|
||||||
cur.moveToFirst();
|
cur.moveToFirst();
|
||||||
entries = cur.getInt(0);
|
entries = cur.getInt(0);
|
||||||
//pd.setMax((int)entries);
|
// pd.setMax((int)entries);
|
||||||
cur.close();
|
cur.close();
|
||||||
|
|
||||||
while (current < entries) {
|
while (current < entries) {
|
||||||
q = "SELECT " + T9DB.COLUMN_ID + ", " + T9DB.COLUMN_WORD + ", " + T9DB.COLUMN_FREQUENCY +
|
q = "SELECT " + T9DB.COLUMN_ID + ", " + T9DB.COLUMN_WORD + ", "
|
||||||
" FROM " + T9DB.WORD_TABLE_NAME +
|
+ T9DB.COLUMN_FREQUENCY + " FROM " + T9DB.WORD_TABLE_NAME + " WHERE "
|
||||||
" WHERE " + T9DB.COLUMN_ID + ">" + current +
|
+ T9DB.COLUMN_ID + ">" + current + " ORDER BY " + T9DB.COLUMN_ID + " LIMIT "
|
||||||
" ORDER BY " + T9DB.COLUMN_ID +
|
+ BACKUP_Q_LIMIT;
|
||||||
" LIMIT " + BACKUP_Q_LIMIT;
|
|
||||||
cur = db.rawQuery(q, null);
|
cur = db.rawQuery(q, null);
|
||||||
for(cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
|
for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
|
||||||
if (isCancelled()) {
|
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.
|
// call onCancelled after this method finishes.
|
||||||
reply.status = false;
|
reply.status = false;
|
||||||
reply.message = "User cancelled.";
|
reply.message = "User cancelled.";
|
||||||
|
|
@ -375,7 +391,7 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
return reply; // why complain? I closed the stream above
|
return reply; // why complain? I closed the stream above
|
||||||
}
|
}
|
||||||
if ((pos - last) > 80) {
|
if ((pos - last) > 80) {
|
||||||
publishProgress((int)((float)current/entries*10000));
|
publishProgress((int) ((float) current / entries * 10000));
|
||||||
last = current;
|
last = current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -384,7 +400,7 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
publishProgress(100);
|
publishProgress(100);
|
||||||
|
|
||||||
endnow = SystemClock.uptimeMillis();
|
endnow = SystemClock.uptimeMillis();
|
||||||
Log.d("TIMING", "Excution time: "+(endnow-startnow)+" ms");
|
Log.d("TIMING", "Excution time: " + (endnow - startnow) + " ms");
|
||||||
Log.d("doInBackground", "entries: " + entries + " last: " + pos);
|
Log.d("doInBackground", "entries: " + entries + " last: " + pos);
|
||||||
db.close();
|
db.close();
|
||||||
try {
|
try {
|
||||||
|
|
@ -396,40 +412,49 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void onProgressUpdate(Integer... progress) {
|
protected void onProgressUpdate(Integer... progress) {
|
||||||
if (pd.isShowing()) {
|
if (pd.isShowing()) {
|
||||||
pd.setProgress(progress[0]);
|
pd.setProgress(progress[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onCancelled() {
|
@Override
|
||||||
// Pointless callback. Thanks android.
|
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) {
|
protected void onPostExecute(Reply result) {
|
||||||
if (pd == null){
|
if (pd == null) {
|
||||||
//Log.d("onPostExecute", "pd");
|
// Log.d("onPostExecute", "pd");
|
||||||
} else {
|
} else {
|
||||||
//Log.d("onPostExecute", "pd");
|
// Log.d("onPostExecute", "pd");
|
||||||
pd.dismiss();
|
pd.dismiss();
|
||||||
}
|
}
|
||||||
if (result == null){
|
if (result == null) {
|
||||||
//bad thing happened
|
// bad thing happened
|
||||||
Log.e("onPostExecute", "Bad things happen?");
|
Log.e("onPostExecute", "Bad things happen?");
|
||||||
} else {
|
} else {
|
||||||
Log.d("onPostExecute", "Result: " + result.status + " " + result.message);
|
Log.d("onPostExecute", "Result: " + result.status + " " + result.message);
|
||||||
if (!result.status) {
|
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> {
|
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) {
|
protected Reply doInBackground(String... ignore) {
|
||||||
Reply reply = new Reply();
|
Reply reply = new Reply();
|
||||||
Log.d("doInBakground", "Nuking dict...");
|
Log.d("doInBakground", "Nuking dict...");
|
||||||
|
|
@ -437,32 +462,37 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
startnow = SystemClock.uptimeMillis();
|
startnow = SystemClock.uptimeMillis();
|
||||||
T9DB t9db = new T9DB(caller);
|
T9DB t9db = new T9DB(caller);
|
||||||
t9db.nuke();
|
t9db.nuke();
|
||||||
|
|
||||||
endnow = SystemClock.uptimeMillis();
|
endnow = SystemClock.uptimeMillis();
|
||||||
Log.d("TIMING", "Excution time: "+(endnow-startnow)+" ms");
|
Log.d("TIMING", "Excution time: " + (endnow - startnow) + " ms");
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onCancelled() {
|
@Override
|
||||||
// Pointless callback. Thanks android.
|
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) {
|
protected void onPostExecute(Reply result) {
|
||||||
if (pd == null){
|
if (pd == null) {
|
||||||
//Log.d("onPostExecute", "pd");
|
// Log.d("onPostExecute", "pd");
|
||||||
} else {
|
} else {
|
||||||
//Log.d("onPostExecute", "pd");
|
// Log.d("onPostExecute", "pd");
|
||||||
pd.dismiss();
|
pd.dismiss();
|
||||||
}
|
}
|
||||||
if (result == null){
|
if (result == null) {
|
||||||
//bad thing happened
|
// bad thing happened
|
||||||
Log.e("onPostExecute", "Bad things happen?");
|
Log.e("onPostExecute", "Bad things happen?");
|
||||||
} else {
|
} else {
|
||||||
Log.d("onPostExecute", "Result: " + result.status + " " + result.message);
|
Log.d("onPostExecute", "Result: " + result.status + " " + result.message);
|
||||||
if (!result.status) {
|
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) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(R.xml.prefs);
|
addPreferencesFromResource(R.xml.prefs);
|
||||||
Preference button = (Preference)getPreferenceManager().findPreference("loaddict");
|
Preference button = getPreferenceManager().findPreference("loaddict");
|
||||||
if (button != null) {
|
if (button != null) {
|
||||||
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -482,7 +512,7 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
button = (Preference)getPreferenceManager().findPreference("nukedict");
|
button = getPreferenceManager().findPreference("nukedict");
|
||||||
if (button != null) {
|
if (button != null) {
|
||||||
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -492,8 +522,8 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
button = (Preference)getPreferenceManager().findPreference("backupdict");
|
button = getPreferenceManager().findPreference("backupdict");
|
||||||
if (button != null) {
|
if (button != null) {
|
||||||
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -503,8 +533,8 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
button = (Preference)getPreferenceManager().findPreference("restoredict");
|
button = getPreferenceManager().findPreference("restoredict");
|
||||||
if (button != null) {
|
if (button != null) {
|
||||||
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -514,8 +544,8 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
button = (Preference)getPreferenceManager().findPreference("querytest");
|
button = getPreferenceManager().findPreference("querytest");
|
||||||
if (button != null) {
|
if (button != null) {
|
||||||
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -525,15 +555,15 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
caller = this;
|
caller = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadDict() {
|
private void loadDict() {
|
||||||
preloader(R.string.pref_loadingdict, "");
|
preloader(R.string.pref_loadingdict, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void preloader(int msgid, String mode){
|
private void preloader(int msgid, String mode) {
|
||||||
pd = new ProgressDialog(this);
|
pd = new ProgressDialog(this);
|
||||||
pd.setMessage(getResources().getString(msgid));
|
pd.setMessage(getResources().getString(msgid));
|
||||||
pd.setOnCancelListener(this);
|
pd.setOnCancelListener(this);
|
||||||
|
|
@ -543,19 +573,19 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
task = new LoadDictTask();
|
task = new LoadDictTask();
|
||||||
task.execute(mode);
|
task.execute(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void predumper(int msgid) {
|
private void predumper(int msgid) {
|
||||||
pd = new ProgressDialog(this);
|
pd = new ProgressDialog(this);
|
||||||
pd.setMessage(getResources().getString(msgid));
|
pd.setMessage(getResources().getString(msgid));
|
||||||
pd.setOnCancelListener(this);
|
pd.setOnCancelListener(this);
|
||||||
//pd.setProgressNumberFormat(null); Why added in API11...
|
// pd.setProgressNumberFormat(null); Why added in API11...
|
||||||
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||||
pd.setMax(10000);
|
pd.setMax(10000);
|
||||||
pd.show();
|
pd.show();
|
||||||
task = new DumpDictTask();
|
task = new DumpDictTask();
|
||||||
task.execute("");
|
task.execute("");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prenuke(int msgid) {
|
private void prenuke(int msgid) {
|
||||||
pd = new ProgressDialog(this);
|
pd = new ProgressDialog(this);
|
||||||
pd.setMessage(getResources().getString(msgid));
|
pd.setMessage(getResources().getString(msgid));
|
||||||
|
|
@ -565,51 +595,51 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
task = new NukeDictTask();
|
task = new NukeDictTask();
|
||||||
task.execute("");
|
task.execute("");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nukeDict() {
|
private void nukeDict() {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setMessage(R.string.pref_nuke_warn)
|
builder.setMessage(R.string.pref_nuke_warn).setTitle(R.string.pref_nuke_title)
|
||||||
.setTitle(R.string.pref_nuke_title)
|
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
prenuke(R.string.pref_nukingdict);
|
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) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void backupDict() {
|
private void backupDict() {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||||
|
|
||||||
File saveloc = new File(Environment.getExternalStorageDirectory(), backupdir);
|
File saveloc = new File(Environment.getExternalStorageDirectory(), backupdir);
|
||||||
saveloc.mkdirs();
|
saveloc.mkdirs();
|
||||||
if (!saveloc.canWrite()){
|
if (!saveloc.canWrite()) {
|
||||||
Log.e("backupDict", "can't write : " + saveloc.getAbsolutePath());
|
Log.e("backupDict", "can't write : " + saveloc.getAbsolutePath());
|
||||||
showErrorDialogID(builder, R.string.pref_backup_title, R.string.pref_backup_noext);
|
showErrorDialogID(builder, R.string.pref_backup_title, R.string.pref_backup_noext);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveloc = new File(saveloc, backupname);
|
saveloc = new File(saveloc, backupname);
|
||||||
if (saveloc.exists()) {
|
if (saveloc.exists()) {
|
||||||
builder.setMessage(R.string.pref_backup_warn)
|
builder.setMessage(R.string.pref_backup_warn).setTitle(R.string.pref_backup_title)
|
||||||
.setTitle(R.string.pref_backup_title)
|
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
predumper(R.string.pref_savingbackup);
|
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) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -619,126 +649,133 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
showErrorDialogID(builder, R.string.pref_backup_title, R.string.pref_backup_noext);
|
showErrorDialogID(builder, R.string.pref_backup_title, R.string.pref_backup_noext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showErrorDialog(String title, String msg) {
|
private void showErrorDialog(String title, String msg) {
|
||||||
showErrorDialog(new AlertDialog.Builder(this), title, msg);
|
showErrorDialog(new AlertDialog.Builder(this), title, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showErrorDialog(AlertDialog.Builder builder, String title, String msg) {
|
private void showErrorDialog(AlertDialog.Builder builder, String title, String msg) {
|
||||||
builder.setMessage(msg)
|
builder.setMessage(msg).setTitle(title)
|
||||||
.setTitle(title)
|
.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showErrorDialogID(AlertDialog.Builder builder, int titleid, int msgid) {
|
private void showErrorDialogID(AlertDialog.Builder builder, int titleid, int msgid) {
|
||||||
builder.setMessage(msgid)
|
builder.setMessage(msgid).setTitle(titleid)
|
||||||
.setTitle(titleid)
|
.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreDict() {
|
private void restoreDict() {
|
||||||
// Environment.MEDIA_MOUNTED_READ_ONLY;
|
// Environment.MEDIA_MOUNTED_READ_ONLY;
|
||||||
// Environment.MEDIA_MOUNTED;
|
// Environment.MEDIA_MOUNTED;
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(Environment.getExternalStorageState()) ||
|
if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(Environment.getExternalStorageState())
|
||||||
Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
|| Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||||
if ((new File(new File(Environment.getExternalStorageDirectory(), backupdir), backupname)).exists()) {
|
if ((new File(new File(Environment.getExternalStorageDirectory(), backupdir),
|
||||||
Resources res = getResources();
|
backupname)).exists()) {
|
||||||
builder.setMessage(res.getString(R.string.pref_restore_warn, res.getString(R.string.pref_nukedict)))
|
Resources res = getResources();
|
||||||
.setTitle(R.string.pref_restore_title)
|
builder
|
||||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
.setMessage(
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
res.getString(R.string.pref_restore_warn,
|
||||||
preloader(R.string.pref_loadingbackup, "backup");
|
res.getString(R.string.pref_nukedict)))
|
||||||
}
|
.setTitle(R.string.pref_restore_title)
|
||||||
})
|
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
dialog.dismiss();
|
preloader(R.string.pref_loadingbackup, "backup");
|
||||||
}
|
}
|
||||||
});
|
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||||
AlertDialog dialog = builder.create();
|
@Override
|
||||||
dialog.show();
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
AlertDialog dialog = builder.create();
|
||||||
|
dialog.show();
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
showErrorDialogID(builder, R.string.pref_restore_title, R.string.pref_restore_noext);
|
showErrorDialogID(builder, R.string.pref_restore_title, R.string.pref_restore_noext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private void queryTestDebug() {
|
private void queryTestDebug() {
|
||||||
long startnow, endnow;
|
long startnow, endnow;
|
||||||
ArrayList<String> words = new ArrayList<String>();
|
ArrayList<String> words = new ArrayList<String>();
|
||||||
ArrayList<Integer> ids = new ArrayList<Integer>();
|
ArrayList<Integer> ids = new ArrayList<Integer>();
|
||||||
|
|
||||||
startnow = SystemClock.uptimeMillis();
|
startnow = SystemClock.uptimeMillis();
|
||||||
|
|
||||||
T9DB tdb = new T9DB(this);
|
T9DB tdb = new T9DB(this);
|
||||||
tdb.init();
|
tdb.init();
|
||||||
Log.d("queryTestDebug", "Testing...");
|
Log.d("queryTestDebug", "Testing...");
|
||||||
tdb.updateWords("123", words, ids, 0);
|
tdb.updateWords("123", words, ids, 0);
|
||||||
Log.d("queryTestDebug", "123->" + words.toString());
|
Log.d("queryTestDebug", "123->" + words.toString());
|
||||||
Log.d("queryTestDebug", "269->");
|
Log.d("queryTestDebug", "269->");
|
||||||
tdb.updateWords("269", words, ids, 0);
|
tdb.updateWords("269", words, ids, 0);
|
||||||
Iterator<String> i = words.iterator();
|
Iterator<String> i = words.iterator();
|
||||||
while (i.hasNext()){
|
while (i.hasNext()) {
|
||||||
Log.d("queryTestDebug", "word: " + i.next());
|
Log.d("queryTestDebug", "word: " + i.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d("queryTestDebug", "228->");
|
Log.d("queryTestDebug", "228->");
|
||||||
tdb.updateWords("228", words, ids, 0);
|
tdb.updateWords("228", words, ids, 0);
|
||||||
i = words.iterator();
|
i = words.iterator();
|
||||||
while (i.hasNext()){
|
while (i.hasNext()) {
|
||||||
Log.d("queryTestDebug", "word: " + i.next());
|
Log.d("queryTestDebug", "word: " + i.next());
|
||||||
}
|
}
|
||||||
endnow = SystemClock.uptimeMillis();
|
endnow = SystemClock.uptimeMillis();
|
||||||
Log.d("TIMING", "Excution time: "+(endnow-startnow)+" ms");
|
Log.d("TIMING", "Excution time: " + (endnow - startnow) + " ms");
|
||||||
tdb.close();
|
tdb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private void queryTest() {
|
private void queryTest() {
|
||||||
long startnow, endnow;
|
long startnow, endnow;
|
||||||
startnow = SystemClock.uptimeMillis();
|
startnow = SystemClock.uptimeMillis();
|
||||||
|
|
||||||
T9DB tdb = new T9DB(this);
|
T9DB tdb = new T9DB(this);
|
||||||
tdb.init();
|
tdb.init();
|
||||||
|
|
||||||
// tdb.getWords("123").iterator();
|
// tdb.getWords("123").iterator();
|
||||||
// tdb.getWords("269").iterator();
|
// tdb.getWords("269").iterator();
|
||||||
// tdb.getWords("228").iterator();
|
// tdb.getWords("228").iterator();
|
||||||
// tdb.getWords("24371").iterator();
|
// tdb.getWords("24371").iterator();
|
||||||
// tdb.getWords("22376284").iterator();
|
// tdb.getWords("22376284").iterator();
|
||||||
// tdb.getWords("68372667367283").iterator();
|
// tdb.getWords("68372667367283").iterator();
|
||||||
// tdb.getWords("22637").iterator();
|
// tdb.getWords("22637").iterator();
|
||||||
|
|
||||||
endnow = SystemClock.uptimeMillis();
|
endnow = SystemClock.uptimeMillis();
|
||||||
Log.d("TIMING", "Excution time: "+(endnow-startnow)+" ms");
|
Log.d("TIMING", "Excution time: " + (endnow - startnow) + " ms");
|
||||||
tdb.close();
|
tdb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queryTestSingle() {
|
private void queryTestSingle() {
|
||||||
long startnow, endnow;
|
long startnow, endnow;
|
||||||
int size;
|
int size;
|
||||||
ArrayList<String> words = new ArrayList<String>(8);
|
ArrayList<String> words = new ArrayList<String>(8);
|
||||||
ArrayList<Integer> ids = new ArrayList<Integer>(8);
|
ArrayList<Integer> ids = new ArrayList<Integer>(8);
|
||||||
startnow = SystemClock.uptimeMillis();
|
startnow = SystemClock.uptimeMillis();
|
||||||
|
|
||||||
T9DB tdb = new T9DB(this);
|
T9DB tdb = new T9DB(this);
|
||||||
tdb.init();
|
tdb.init();
|
||||||
|
|
||||||
tdb.updateWords("222", words, ids, 0);
|
tdb.updateWords("222", words, ids, 0);
|
||||||
size = ids.size();
|
size = ids.size();
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
|
|
@ -746,26 +783,26 @@ public class TraditionalT9Settings extends PreferenceActivity implements
|
||||||
tdb.incrementWord(ids.get(0));
|
tdb.incrementWord(ids.get(0));
|
||||||
tdb.incrementWord(ids.get(0));
|
tdb.incrementWord(ids.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int x=0; x<size; x++){
|
for (int x = 0; x < size; x++) {
|
||||||
tdb.incrementWord(ids.get(x));
|
tdb.incrementWord(ids.get(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
endnow = SystemClock.uptimeMillis();
|
endnow = SystemClock.uptimeMillis();
|
||||||
Log.d("TIMING", "Excution time: "+(endnow-startnow)+" ms");
|
Log.d("TIMING", "Excution time: " + (endnow - startnow) + " ms");
|
||||||
|
|
||||||
ArrayList<Integer> freqs = new ArrayList<Integer>(8);
|
ArrayList<Integer> freqs = new ArrayList<Integer>(8);
|
||||||
tdb.updateWordsW("222", words, ids, freqs);
|
tdb.updateWordsW("222", words, ids, freqs);
|
||||||
Log.d("VALUES", "...");
|
Log.d("VALUES", "...");
|
||||||
size = freqs.size();
|
size = freqs.size();
|
||||||
for (int x = 0; x < size; x++){
|
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.");
|
Log.d("queryTestSingle", "done.");
|
||||||
tdb.close();
|
tdb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dint) {
|
public void onCancel(DialogInterface dint) {
|
||||||
task.cancel(false);
|
task.cancel(false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue