Improves the Android text handling

git-svn-id: trunk@34571 -
This commit is contained in:
sekelsenmat 2012-01-04 11:21:28 +00:00
parent 621e42afef
commit cc4b062b1d
3 changed files with 68 additions and 6 deletions

View File

@ -6,8 +6,9 @@ import android.os.*;
import android.widget.*;
import android.util.*;
import android.graphics.*;
import android.text.*;
import android.view.*;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.*;
import android.content.res.Configuration;
import android.content.Intent;
import android.hardware.Sensor;
@ -22,6 +23,47 @@ import java.util.*;
public class LCLActivity extends Activity implements SensorEventListener, LocationListener
{
// -------------------------------------------
// Input connection to get character events
// -------------------------------------------
private class LCLInputConnection extends BaseInputConnection
{
private SpannableStringBuilder _editable;
View _lclView;
public LCLInputConnection(View targetView, boolean fullEditor)
{
super(targetView, fullEditor);
_lclView = (View) targetView;
}
/* public Editable getEditable()
{
if (_editable == null)
{
_editable = (SpannableStringBuilder) Editable.Factory.getInstance()
.newEditable("Placeholder");
}
return _editable;
} This crashes in HTC */
// This method sends a text to be added at the current cursor position
public boolean commitText(CharSequence text, int newCursorPosition)
{
//if (_editable != null) _editable.append(text);
Log.v("lclproject", "LCLInputConnection.commitText =" + text);
// Send each character of the string
int eventResult, i;
for (i = 0; i<text.length(); i++)
{
eventResult = LCLOnKey(-1, 0, null, (int) text.charAt(i));
if ((eventResult & 1) != 0) lclsurface.postInvalidate();
}
return true;
}
}
// -------------------------------------------
// Our drawing surface
// -------------------------------------------
@ -100,6 +142,20 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
if ((eventResult | 1) != 0) postInvalidate();
return true;
}
@Override public InputConnection onCreateInputConnection(EditorInfo outAttrs)
{
outAttrs.actionLabel = null;
outAttrs.label = "Test text";
outAttrs.inputType = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE;
return new LCLInputConnection(this, true);
}
@Override public boolean onCheckIsTextEditor()
{
return true;
}
}
// Global objects

View File

@ -1,5 +1,5 @@
object Form2: TForm2
Left = 154
Left = 236
Height = 259
Top = 137
Width = 320

View File

@ -144,14 +144,20 @@ begin
case AKind of
ACTION_DOWN: CallbackKeyDown(lCurForm, lKey);
-1: // This indicates a key char event
begin
AUTF8Text := UnicodeToUTF8(lChar);
AUTF8Char := AUTF8Text;
CallbackKeyChar(lCurForm, lKey, AUTF8Char);
end;
ACTION_UP:
begin
CallbackKeyUp(lCurForm, lKey);
if (lChar <> 0) and ((COMBINING_ACCENT and lChar) = 0) then
(* if (lChar <> 0) and ((COMBINING_ACCENT and lChar) = 0) then
begin
if CDWidgetset.CombiningAccent <> 0 then
begin
(* // Prepare the input
// Prepare the input
lJavaString :=javaEnvRef^^.NewStringUTF(javaEnvRef, Str);
javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, JavaField_lcltext, lJavaString);
javaEnvRef^^.SetIntField(javaEnvRef, javaActivityObject, javaField_lcltextsize, lFontSize);
@ -163,7 +169,7 @@ begin
Size.cx := javaEnvRef^^.GetIntField(javaEnvRef, javaActivityObject, javaField_lclwidth);
Size.cy := javaEnvRef^^.GetIntField(javaEnvRef, javaActivityObject, javaField_lclheight);
//
lCombinedAChar := getDeadChar();*)
lCombinedAChar := getDeadChar();
end;
AUTF8Text := UnicodeToUTF8(lChar);
AUTF8Char := AUTF8Text;
@ -173,7 +179,7 @@ begin
else if (lChar <> 0) and ((COMBINING_ACCENT and lChar) <> 0) then
begin
CDWidgetset.CombiningAccent := lChar;
end;
end;*)
// Handle the Back hardware key
if AKeyCode = AKEYCODE_BACK then