<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -18,7 +18,7 @@ public abstract class IKerKerInputMethod {
 
 	/* Keyboard Events */
 	public Keyboard getDesiredKeyboard() { return null; }
-	public boolean wantHandleEvent(int keyCode) { return (keyCode &gt; -2); }
+	public boolean wantHandleEvent(int keyCode) { return (keyCode &gt; -2) || (keyCode == Keyboard.KEYCODE_DELETE) ; }
 	abstract public boolean onKeyEvent(int keyCode, int[] keyCodes);
 	abstract public void commitCandidate(int currentCandidate);
 	public void onTextEvent(CharSequence text) { if (_core != null) _core.getConnection().commitText(text, 1); }</diff>
      <filename>src/idv/Zero/KerKerInput/IKerKerInputMethod.java</filename>
    </modified>
    <modified>
      <diff>@@ -10,6 +10,10 @@ public class KBManager {
 	public static final int KEYCODE_IME = -103;
 	public static final int KEYCODE_NEXT_IME = -104;
 	public static final int KEYCODE_DO_OUTPUT_CHARS = -105;
+	public static final int KEYCODE_DPAD_UP = -106;
+	public static final int KEYCODE_DPAD_DOWN = -107;
+	public static final int KEYCODE_DPAD_LEFT = -108;
+	public static final int KEYCODE_DPAD_RIGHT = -109;
 	
 	private KerKerInputCore _core = null;
 	private KeyboardView _currentKBView = null;</diff>
      <filename>src/idv/Zero/KerKerInput/KBManager.java</filename>
    </modified>
    <modified>
      <diff>@@ -138,12 +138,34 @@ public class KerKerInputCore implements OnKeyboardActionListener {
 		// Allow user to user BACK key to hide SIP
 		if (e.getKeyCode() == KeyEvent.KEYCODE_BACK)
 			return false;
-		else if (e.getKeyCode() == KeyEvent.KEYCODE_MENU)
-			return false;
-		else if (e.getKeyCode() == KeyEvent.KEYCODE_ALT_LEFT)
-			requestNextInputMethod();
 		
-		return _currentMethod.onKeyEvent(keyCode, new int[]{keyCode});
+		if (_currentMethod.wantHandleEvent(e.getKeyCode()))
+			_currentMethod.onKeyEvent(keyCode, new int[]{keyCode});
+		else
+		{
+			switch(e.getKeyCode())
+			{
+			case KeyEvent.KEYCODE_MENU:
+				return false;
+			case KeyEvent.KEYCODE_ALT_LEFT:
+				requestNextInputMethod();
+				break;
+			case KBManager.KEYCODE_DPAD_UP:
+				getFrontend().sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_UP);
+				break;
+			case KBManager.KEYCODE_DPAD_DOWN:
+				getFrontend().sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_DOWN);
+				break;
+			case KBManager.KEYCODE_DPAD_LEFT:
+				getFrontend().sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT);
+				break;
+			case KBManager.KEYCODE_DPAD_RIGHT:
+				getFrontend().sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT);
+				break;
+			}
+		}
+		
+		return false;
 	}
 	
 	public boolean onKeyMultiple(int keyCode, int count, KeyEvent e)
@@ -177,16 +199,19 @@ public class KerKerInputCore implements OnKeyboardActionListener {
 				_currentMode = InputMode.MODE_SYM;
 				_kbm.setNativeKeyboard(NativeKeyboardTypes.MODE_SYM);
 				showIMENamePopup(&quot;123&quot;);
+				hideCandidatesView();
 				break;
 			case KBManager.KEYCODE_SYM_ALT: // 123 Keyboard
 				_currentMode = InputMode.MODE_SYM_ALT;
 				_kbm.setNativeKeyboard(NativeKeyboardTypes.MODE_SYM_ALT);
 				showIMENamePopup(&quot;#+=&quot;);
+				hideCandidatesView();
 				break;
 			case KBManager.KEYCODE_ABC: // ABC Keyboard
 				_currentMode = InputMode.MODE_ABC;
 				_kbm.setNativeKeyboard(NativeKeyboardTypes.MODE_ABC);
 				showIMENamePopup(&quot;ABC&quot;);
+				hideCandidatesView();
 				break;
 			case KBManager.KEYCODE_IME: // IME Keyboard
 				_currentMode = InputMode.MODE_IME;
@@ -238,7 +263,9 @@ public class KerKerInputCore implements OnKeyboardActionListener {
 	}
 	
 	public void hideCandidatesView() {
-		_frontEnd.setCandidatesViewShown(false);
+		//_frontEnd.setCandidatesViewShown(false);
+		if (_candidatesContainer != null)
+			clearCandidates();
 	}
 	
 	public void setCompositeBuffer(CharSequence buf) {</diff>
      <filename>src/idv/Zero/KerKerInput/KerKerInputCore.java</filename>
    </modified>
    <modified>
      <diff>@@ -62,13 +62,13 @@ public class KerKerInputService extends InputMethodService {
 		if (e.getKeyCode() == KeyEvent.KEYCODE_DEL)
 			return -5;
 		else if (e.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP)
-			return -100;
+			return KBManager.KEYCODE_DPAD_UP;
 		else if (e.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN)
-			return -101;
+			return KBManager.KEYCODE_DPAD_DOWN;
 		else if (e.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT)
-			return -102;
+			return KBManager.KEYCODE_DPAD_LEFT;
 		else if (e.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT)
-			return -103;
+			return KBManager.KEYCODE_DPAD_RIGHT;
 		
 		return e.getUnicodeChar();
 	}</diff>
      <filename>src/idv/Zero/KerKerInput/KerKerInputService.java</filename>
    </modified>
    <modified>
      <diff>@@ -80,6 +80,8 @@ public class BPMFInput extends idv.Zero.KerKerInput.IKerKerInputMethod {
 	public void onEnterInputMethod()
 	{
 		currentState = InputState.STATE_INPUT;
+		inputBufferRaw = &quot;&quot;;
+		updateCandidates();
 	}
 	
 	public void destroyInputMethod()
@@ -112,15 +114,22 @@ public class BPMFInput extends idv.Zero.KerKerInput.IKerKerInputMethod {
 				else
 					_core.getFrontend().sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
 			}
-			else if(keyCode == 32) { // space
+			else if (keyCode == 32) // space
+			{
 				if (_currentCandidates.size() &gt; 0)
+				{
 					currentState = InputState.STATE_CHOOSE;
+					handleBPMFKeyEvent(32, null);
+				}
 				else
 					_core.getFrontend().sendKeyChar((char) keyCode);
 			}
-			else if(keyCode &gt;= -104 &amp;&amp; keyCode &lt;= -100)
+			else if (keyCode == 10) // RETURN
 			{
-				return false;
+				if (inputBufferRaw.length() &gt; 0)
+					commitText(getCompositeString());
+				else
+					_core.getFrontend().sendKeyChar((char) keyCode);
 			}
 			else
 			{
@@ -150,19 +159,22 @@ public class BPMFInput extends idv.Zero.KerKerInput.IKerKerInputMethod {
 					Log.e(&quot;BPMFInput&quot;, &quot;InputBuffer is requested to delete, but the buffer is empty&quot;);
 				
 				break;
+			// TODO: Make sure DPad &amp; Keyboard L/R keyCode
 			case -103: // DPad Left
 				if (_currentPage &gt; 0)
 					_currentPage--;
 				else
 					_currentPage = _totalPages - 1;
 				break;
-			case ' ':
 			case -104: // DPad Right
 				if (_currentPage &lt; _totalPages - 1)
 					_currentPage++;
 				else
 					_currentPage = 0;
 				break;
+			case ' ':
+			case 10:
+				keyCode = KeyEvent.KEYCODE_0;
 			default:
 				if (keyCode &gt;= KeyEvent.KEYCODE_0 &amp;&amp; keyCode &lt;= KeyEvent.KEYCODE_9)
 				{
@@ -173,8 +185,6 @@ public class BPMFInput extends idv.Zero.KerKerInput.IKerKerInputMethod {
 				    if ((_currentPage * CANDIDATES_PER_PAGE + keyCode - KeyEvent.KEYCODE_0 - 1) &lt; _currentCandidates.size())
 				    {
 				        commitCandidate(_currentPage * CANDIDATES_PER_PAGE + keyCode - KeyEvent.KEYCODE_0 - 1);
-				        currentState = InputState.STATE_INPUT;
-				        inputBufferRaw = &quot;&quot;;
 				    }
 				}
 				break;
@@ -205,7 +215,8 @@ public class BPMFInput extends idv.Zero.KerKerInput.IKerKerInputMethod {
 		
 		try
 		{
-			Cursor currentQuery = db.rawQuery(&quot;Select val from bpmf where key glob '&quot; + inputBufferRaw.toString() + &quot;*'&quot;, null);
+			// Cursor currentQuery = db.rawQuery(&quot;Select val from bpmf where key glob '&quot; + inputBufferRaw.toString() + &quot;*'&quot;, null);
+			Cursor currentQuery = db.rawQuery(&quot;Select val from bpmf where key &gt;= '&quot; + inputBufferRaw.toString() + &quot;' AND key &lt; '&quot; + inputBufferRaw.toString() + &quot;zzz'&quot;, null);
 			if (currentQuery.getCount() == 0)
 			{
 				inputBufferRaw = inputBufferRaw.substring(0, inputBufferRaw.length() - 1);
@@ -240,13 +251,11 @@ public class BPMFInput extends idv.Zero.KerKerInput.IKerKerInputMethod {
 		}
 	}
 
-	public void commitCandidate(int selectedCandidate) {
-		_core.getConnection().commitText(_currentCandidates.get(selectedCandidate), 1);
-		_core.hideCandidatesView();
-		inputBufferRaw = &quot;&quot;;
-		currentState = InputState.STATE_INPUT;
+	public void commitCandidate(int selectedCandidate)
+	{
+		commitText(_currentCandidates.get(selectedCandidate));
 	}
-	
+		
 	public void setTotalPages(int totalPages)
 	{
 		_totalPages = totalPages;
@@ -257,6 +266,15 @@ public class BPMFInput extends idv.Zero.KerKerInput.IKerKerInputMethod {
 		_currentPage = currentPage;
 	}
 	
+	private void commitText(CharSequence str)
+	{
+		_core.getConnection().commitText(str, 1);
+		_core.hideCandidatesView();
+		inputBufferRaw = &quot;&quot;;
+		updateCandidates();
+		currentState = InputState.STATE_INPUT;
+	}
+	
 	private void initKeyNameData()
 	{
 		K2N = new HashMap&lt;Character, String&gt;();			</diff>
      <filename>src/idv/Zero/KerKerInput/Methods/BPMFInput.java</filename>
    </modified>
    <modified>
      <diff>@@ -42,6 +42,7 @@ public class NoSeeing extends idv.Zero.KerKerInput.IKerKerInputMethod {
 		}
 		catch(SQLiteException ex)
 		{
+			db = null;
 			System.out.println(&quot;Error, no database file found. Copying...&quot;);
 
 			new Thread(new Runnable() {
@@ -64,18 +65,24 @@ public class NoSeeing extends idv.Zero.KerKerInput.IKerKerInputMethod {
 					} catch (IOException e) {
 						e.printStackTrace();
 					}
-				}
+
+					db = SQLiteDatabase.openDatabase(_dbpath, null, SQLiteDatabase.OPEN_READONLY);
+					db.setLocale(Locale.TRADITIONAL_CHINESE);
+			}
 			}).start();
 		}
 	}
 	
 	public void onEnterInputMethod()
 	{
+		inputBufferRaw.delete(0, inputBufferRaw.length());
+		updateCandidates();
 	}
 	
 	public void destroyInputMethod()
 	{
-		db.close();
+		if (db != null)
+			db.close();
 	}
 	
 	public String getName()
@@ -101,11 +108,14 @@ public class NoSeeing extends idv.Zero.KerKerInput.IKerKerInputMethod {
 			else
 				_core.getFrontend().sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
 		}
-		else if(keyCode &gt;= -104 &amp;&amp; keyCode &lt;= -100)
+		else if (keyCode == 10)
 		{
-			return false;
+			if (inputBufferRaw.length() &gt; 0)
+				commitText(getCompositeString());
+			else
+				_core.getFrontend().sendKeyChar((char) keyCode);
 		}
-		else if((keyCode &gt;= KeyEvent.KEYCODE_0 &amp;&amp; keyCode &lt;= KeyEvent.KEYCODE_9) || keyCode == 32)
+		else if(((keyCode &gt;= KeyEvent.KEYCODE_0 &amp;&amp; keyCode &lt;= KeyEvent.KEYCODE_9) || (keyCode == 32)) &amp;&amp; inputBufferRaw.length() &gt; 0)
 		{
 			// Noseeing users tend to use SPACE to select first candidate
 			if (keyCode == 32)
@@ -155,11 +165,13 @@ public class NoSeeing extends idv.Zero.KerKerInput.IKerKerInputMethod {
 			return;
 		}
 		
+		if (db == null)
+			return;
+		
 		try
 		{
-			db = SQLiteDatabase.openDatabase(_dbpath, null, SQLiteDatabase.OPEN_READONLY);
-			db.setLocale(Locale.TRADITIONAL_CHINESE);
-			Cursor currentQuery = db.rawQuery(&quot;Select val from noseeing where key glob '&quot; + inputBufferRaw.toString() + &quot;*'&quot;, null);
+			//Cursor currentQuery = db.rawQuery(&quot;Select val from noseeing where key glob '&quot; + inputBufferRaw.toString() + &quot;*'&quot;, null);
+			Cursor currentQuery = db.rawQuery(&quot;Select val from noseeing where key &gt;= '&quot; + inputBufferRaw.toString() + &quot;' AND key &lt; '&quot; + inputBufferRaw.toString() + &quot;zzz'&quot;, null);
 			if (currentQuery.getCount() == 0)
 			{
 				inputBufferRaw.deleteCharAt(inputBufferRaw.length() - 1);
@@ -184,19 +196,24 @@ public class NoSeeing extends idv.Zero.KerKerInput.IKerKerInputMethod {
 					currentQuery.moveToNext();
 				}
 				
-				_core.showCandidatesView();
 				_core.setCandidates(_currentCandidates);
+				_core.showCandidatesView();
 			}
 		}
 		catch(Exception e) {}
 		finally
 		{
-			db.close();
 		}
 	}
 
-	public void commitCandidate(int selectedCandidate) {
-		_core.getConnection().commitText(_currentCandidates.get(selectedCandidate), 1);
+	public void commitCandidate(int selectedCandidate)
+	{
+		commitText(_currentCandidates.get(selectedCandidate));
+	}
+	
+	private void commitText(CharSequence str)
+	{
+		_core.getConnection().commitText(str, 1);
 		_core.hideCandidatesView();
 		inputBufferRaw.delete(0, inputBufferRaw.length());
 	}</diff>
      <filename>src/idv/Zero/KerKerInput/Methods/NoSeeing.java</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>07288dab0807d0878fb68464d26e6cd1533a3908</id>
    </parent>
  </parents>
  <author>
    <name>itsZero (Chien-An &quot;Zero&quot; Cho)</name>
    <email>itsero@gmail.com</email>
  </author>
  <url>http://github.com/itszero/KerKerInput/commit/f8ab0393c9dafdb9fbdada9ff76fca7af14b905f</url>
  <id>f8ab0393c9dafdb9fbdada9ff76fca7af14b905f</id>
  <committed-date>2009-09-29T09:18:46-07:00</committed-date>
  <authored-date>2009-09-29T09:18:46-07:00</authored-date>
  <message>Abstracted the common keycode processing to the Core.
Add common-used KKI-customized keycode to KBManager</message>
  <tree>b16490f0dadb2997a9d6f3748b8473b80c00a0ed</tree>
  <committer>
    <name>itsZero (Chien-An &quot;Zero&quot; Cho)</name>
    <email>itsero@gmail.com</email>
  </committer>
</commit>
