mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 17:19:23 +02:00
Improves the Android text handling
git-svn-id: trunk@34571 -
This commit is contained in:
parent
621e42afef
commit
cc4b062b1d
@ -6,8 +6,9 @@ import android.os.*;
|
|||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
|
import android.text.*;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.*;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
@ -22,6 +23,47 @@ import java.util.*;
|
|||||||
|
|
||||||
public class LCLActivity extends Activity implements SensorEventListener, LocationListener
|
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
|
// Our drawing surface
|
||||||
// -------------------------------------------
|
// -------------------------------------------
|
||||||
@ -100,6 +142,20 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
if ((eventResult | 1) != 0) postInvalidate();
|
if ((eventResult | 1) != 0) postInvalidate();
|
||||||
return true;
|
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
|
// Global objects
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
object Form2: TForm2
|
object Form2: TForm2
|
||||||
Left = 154
|
Left = 236
|
||||||
Height = 259
|
Height = 259
|
||||||
Top = 137
|
Top = 137
|
||||||
Width = 320
|
Width = 320
|
||||||
|
@ -144,14 +144,20 @@ begin
|
|||||||
|
|
||||||
case AKind of
|
case AKind of
|
||||||
ACTION_DOWN: CallbackKeyDown(lCurForm, lKey);
|
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:
|
ACTION_UP:
|
||||||
begin
|
begin
|
||||||
CallbackKeyUp(lCurForm, lKey);
|
CallbackKeyUp(lCurForm, lKey);
|
||||||
if (lChar <> 0) and ((COMBINING_ACCENT and lChar) = 0) then
|
(* if (lChar <> 0) and ((COMBINING_ACCENT and lChar) = 0) then
|
||||||
begin
|
begin
|
||||||
if CDWidgetset.CombiningAccent <> 0 then
|
if CDWidgetset.CombiningAccent <> 0 then
|
||||||
begin
|
begin
|
||||||
(* // Prepare the input
|
// Prepare the input
|
||||||
lJavaString :=javaEnvRef^^.NewStringUTF(javaEnvRef, Str);
|
lJavaString :=javaEnvRef^^.NewStringUTF(javaEnvRef, Str);
|
||||||
javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, JavaField_lcltext, lJavaString);
|
javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, JavaField_lcltext, lJavaString);
|
||||||
javaEnvRef^^.SetIntField(javaEnvRef, javaActivityObject, javaField_lcltextsize, lFontSize);
|
javaEnvRef^^.SetIntField(javaEnvRef, javaActivityObject, javaField_lcltextsize, lFontSize);
|
||||||
@ -163,7 +169,7 @@ begin
|
|||||||
Size.cx := javaEnvRef^^.GetIntField(javaEnvRef, javaActivityObject, javaField_lclwidth);
|
Size.cx := javaEnvRef^^.GetIntField(javaEnvRef, javaActivityObject, javaField_lclwidth);
|
||||||
Size.cy := javaEnvRef^^.GetIntField(javaEnvRef, javaActivityObject, javaField_lclheight);
|
Size.cy := javaEnvRef^^.GetIntField(javaEnvRef, javaActivityObject, javaField_lclheight);
|
||||||
//
|
//
|
||||||
lCombinedAChar := getDeadChar();*)
|
lCombinedAChar := getDeadChar();
|
||||||
end;
|
end;
|
||||||
AUTF8Text := UnicodeToUTF8(lChar);
|
AUTF8Text := UnicodeToUTF8(lChar);
|
||||||
AUTF8Char := AUTF8Text;
|
AUTF8Char := AUTF8Text;
|
||||||
@ -173,7 +179,7 @@ begin
|
|||||||
else if (lChar <> 0) and ((COMBINING_ACCENT and lChar) <> 0) then
|
else if (lChar <> 0) and ((COMBINING_ACCENT and lChar) <> 0) then
|
||||||
begin
|
begin
|
||||||
CDWidgetset.CombiningAccent := lChar;
|
CDWidgetset.CombiningAccent := lChar;
|
||||||
end;
|
end;*)
|
||||||
|
|
||||||
// Handle the Back hardware key
|
// Handle the Back hardware key
|
||||||
if AKeyCode = AKEYCODE_BACK then
|
if AKeyCode = AKEYCODE_BACK then
|
||||||
|
Loading…
Reference in New Issue
Block a user