mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-12 12:28:29 +02:00
Implements basic accelerometer support in Android and adds it to the Example
git-svn-id: trunk@34479 -
This commit is contained in:
parent
b03ad1543e
commit
b360c1f433
@ -9,9 +9,15 @@ import android.graphics.*;
|
|||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.hardware.Sensor;
|
||||||
|
import android.hardware.SensorEvent;
|
||||||
|
import android.hardware.SensorEventListener;
|
||||||
|
import android.hardware.SensorManager;
|
||||||
|
|
||||||
public class LCLActivity extends Activity
|
public class LCLActivity extends Activity implements SensorEventListener
|
||||||
{
|
{
|
||||||
|
private SensorManager localSensorManager;
|
||||||
|
|
||||||
// -------------------------------------------
|
// -------------------------------------------
|
||||||
// Our drawing surface
|
// Our drawing surface
|
||||||
// -------------------------------------------
|
// -------------------------------------------
|
||||||
@ -147,6 +153,7 @@ public class LCLActivity extends Activity
|
|||||||
public native int LCLOnKey(int kind, int keyCode, KeyEvent event, char AChar);
|
public native int LCLOnKey(int kind, int keyCode, KeyEvent event, char AChar);
|
||||||
public native int LCLOnTimer(Runnable timerid);
|
public native int LCLOnTimer(Runnable timerid);
|
||||||
public native int LCLOnConfigurationChanged(int ANewDPI, int ANewWidth);
|
public native int LCLOnConfigurationChanged(int ANewDPI, int ANewWidth);
|
||||||
|
public native int LCLOnSensorChanged(int ASensorKind, float[] AValues);
|
||||||
|
|
||||||
// -------------------------------------------
|
// -------------------------------------------
|
||||||
// Functions exported to the Pascal side
|
// Functions exported to the Pascal side
|
||||||
@ -309,6 +316,32 @@ public class LCLActivity extends Activity
|
|||||||
localInputManager.showSoftInput(lclsurface, 0);
|
localInputManager.showSoftInput(lclsurface, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSensorChanged(SensorEvent event)
|
||||||
|
{
|
||||||
|
int eventKind = event.sensor.getType();
|
||||||
|
int eventResult = LCLOnSensorChanged(eventKind, event.values);
|
||||||
|
if (((eventResult | 1) != 0) && (lclsurface != null)) lclsurface.postInvalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAccuracyChanged(Sensor sensor, int accuracy)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LCLDoStartReadingAccelerometer()
|
||||||
|
{
|
||||||
|
localSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
|
||||||
|
localSensorManager.registerListener(this,
|
||||||
|
localSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
|
||||||
|
SensorManager.SENSOR_DELAY_NORMAL);
|
||||||
|
};
|
||||||
|
|
||||||
|
public void LCLDoStopReadingAccelerometer()
|
||||||
|
{
|
||||||
|
localSensorManager.unregisterListener(this);
|
||||||
|
};
|
||||||
|
|
||||||
// -------------------------------------------
|
// -------------------------------------------
|
||||||
// Fields exported to the Pascal side for easier data communication
|
// Fields exported to the Pascal side for easier data communication
|
||||||
// -------------------------------------------
|
// -------------------------------------------
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
</Target>
|
</Target>
|
||||||
<SearchPaths>
|
<SearchPaths>
|
||||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
<Libraries Value="/home/felipe/Programas/android-ndk-r5/platforms/android-8/arch-arm/usr/lib;/home/felipe/Programas/android-ndk-r5/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/lib/gcc/arm-eabi/4.4.0"/>
|
<Libraries Value="/home/felipe/Programas/android-ndk-r5/platforms/android-8/arch-arm/usr/lib/;/home/felipe/Programas/android-ndk-r5/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/lib/gcc/arm-eabi/4.4.0/"/>
|
||||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
<CodeGeneration>
|
<CodeGeneration>
|
||||||
@ -72,7 +72,7 @@
|
|||||||
</Target>
|
</Target>
|
||||||
<SearchPaths>
|
<SearchPaths>
|
||||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
<Libraries Value="C:/Programas/android-ndk-r7/platforms/android-8/arch-arm/usr/lib/"/>
|
<Libraries Value="C:/Programas/android-ndk-r7/platforms/android-8/arch-arm/usr/lib"/>
|
||||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
<CodeGeneration>
|
<CodeGeneration>
|
||||||
@ -150,7 +150,7 @@
|
|||||||
</Target>
|
</Target>
|
||||||
<SearchPaths>
|
<SearchPaths>
|
||||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
<Libraries Value="/home/felipe/Programas/android-ndk-r5/platforms/android-8/arch-arm/usr/lib;/home/felipe/Programas/android-ndk-r5/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/lib/gcc/arm-eabi/4.4.0"/>
|
<Libraries Value="/home/felipe/Programas/android-ndk-r5/platforms/android-8/arch-arm/usr/lib/;/home/felipe/Programas/android-ndk-r5/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/lib/gcc/arm-eabi/4.4.0/"/>
|
||||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
<CodeGeneration>
|
<CodeGeneration>
|
||||||
|
@ -15,7 +15,8 @@ exports
|
|||||||
Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished name 'Java_com_pascal_lcltest_LCLActivity_LCLOnMessageBoxFinished',
|
Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished name 'Java_com_pascal_lcltest_LCLActivity_LCLOnMessageBoxFinished',
|
||||||
Java_com_pascal_lclproject_LCLActivity_LCLOnKey name 'Java_com_pascal_lcltest_LCLActivity_LCLOnKey',
|
Java_com_pascal_lclproject_LCLActivity_LCLOnKey name 'Java_com_pascal_lcltest_LCLActivity_LCLOnKey',
|
||||||
Java_com_pascal_lclproject_LCLActivity_LCLOnTimer name 'Java_com_pascal_lcltest_LCLActivity_LCLOnTimer',
|
Java_com_pascal_lclproject_LCLActivity_LCLOnTimer name 'Java_com_pascal_lcltest_LCLActivity_LCLOnTimer',
|
||||||
Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged name 'Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged',
|
Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged name 'Java_com_pascal_lcltest_LCLActivity_LCLOnConfigurationChanged',
|
||||||
|
Java_com_pascal_lclproject_LCLActivity_LCLOnSensorChanged name 'Java_com_pascal_lcltest_LCLActivity_LCLOnSensorChanged',
|
||||||
JNI_OnLoad name 'JNI_OnLoad',
|
JNI_OnLoad name 'JNI_OnLoad',
|
||||||
JNI_OnUnload name 'JNI_OnUnload';
|
JNI_OnUnload name 'JNI_OnUnload';
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
object Form1: TForm1
|
object Form1: TForm1
|
||||||
Left = 932
|
Left = 161
|
||||||
Height = 251
|
Height = 251
|
||||||
Top = 220
|
Top = 137
|
||||||
Width = 220
|
Width = 220
|
||||||
Caption = 'Form1'
|
Caption = 'Form1'
|
||||||
ClientHeight = 251
|
ClientHeight = 251
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
object Form2: TForm2
|
object Form2: TForm2
|
||||||
Left = 1158
|
Left = 154
|
||||||
Height = 259
|
Height = 259
|
||||||
Top = 220
|
Top = 137
|
||||||
Width = 320
|
Width = 320
|
||||||
Caption = 'Form2'
|
Caption = 'Form2'
|
||||||
ClientHeight = 259
|
ClientHeight = 259
|
||||||
@ -10,7 +10,7 @@ object Form2: TForm2
|
|||||||
object Button1: TButton
|
object Button1: TButton
|
||||||
Left = 8
|
Left = 8
|
||||||
Height = 25
|
Height = 25
|
||||||
Top = 16
|
Top = 0
|
||||||
Width = 304
|
Width = 304
|
||||||
Caption = 'Hide'
|
Caption = 'Hide'
|
||||||
OnClick = Button1Click
|
OnClick = Button1Click
|
||||||
@ -19,7 +19,7 @@ object Form2: TForm2
|
|||||||
object Edit1: TEdit
|
object Edit1: TEdit
|
||||||
Left = 12
|
Left = 12
|
||||||
Height = 25
|
Height = 25
|
||||||
Top = 50
|
Top = 32
|
||||||
Width = 80
|
Width = 80
|
||||||
OnExit = Edit1Exit
|
OnExit = Edit1Exit
|
||||||
OnKeyDown = Edit1KeyDown
|
OnKeyDown = Edit1KeyDown
|
||||||
@ -29,10 +29,10 @@ object Form2: TForm2
|
|||||||
Text = 'Edit1'
|
Text = 'Edit1'
|
||||||
end
|
end
|
||||||
object Image1: TImage
|
object Image1: TImage
|
||||||
Left = 32
|
Left = 96
|
||||||
Height = 138
|
Height = 138
|
||||||
Top = 96
|
Top = 32
|
||||||
Width = 274
|
Width = 210
|
||||||
Picture.Data = {
|
Picture.Data = {
|
||||||
07545069786D617044DA00002F2A2058504D202A2F0A73746174696320636861
|
07545069786D617044DA00002F2A2058504D202A2F0A73746174696320636861
|
||||||
72202A206C617A617275735F61626F75745F6C6F676F5F78706D5B5D203D207B
|
72202A206C617A617275735F61626F75745F6C6F676F5F78706D5B5D203D207B
|
||||||
@ -1783,4 +1783,21 @@ object Form2: TForm2
|
|||||||
2E202E202E202E202E202E20227D3B0A
|
2E202E202E202E202E202E20227D3B0A
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
object Button2: TButton
|
||||||
|
Left = 8
|
||||||
|
Height = 25
|
||||||
|
Top = 194
|
||||||
|
Width = 304
|
||||||
|
Caption = 'Read Accelerometer'
|
||||||
|
OnClick = Button2Click
|
||||||
|
TabOrder = 2
|
||||||
|
end
|
||||||
|
object labelSensorData: TLabel
|
||||||
|
Left = 8
|
||||||
|
Height = 18
|
||||||
|
Top = 168
|
||||||
|
Width = 81
|
||||||
|
Caption = 'Sensor Data'
|
||||||
|
ParentColor = False
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
||||||
ComCtrls, ExtCtrls, LCLType, LCLProc;
|
ComCtrls, ExtCtrls, LCLType, LCLProc, lazdeviceapis;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -14,9 +14,12 @@ type
|
|||||||
|
|
||||||
TForm2 = class(TForm)
|
TForm2 = class(TForm)
|
||||||
Button1: TButton;
|
Button1: TButton;
|
||||||
|
Button2: TButton;
|
||||||
Edit1: TEdit;
|
Edit1: TEdit;
|
||||||
Image1: TImage;
|
Image1: TImage;
|
||||||
|
labelSensorData: TLabel;
|
||||||
procedure Button1Click(Sender: TObject);
|
procedure Button1Click(Sender: TObject);
|
||||||
|
procedure Button2Click(Sender: TObject);
|
||||||
procedure Edit1Exit(Sender: TObject);
|
procedure Edit1Exit(Sender: TObject);
|
||||||
procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||||
procedure Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
|
procedure Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||||
@ -25,6 +28,7 @@ type
|
|||||||
{ private declarations }
|
{ private declarations }
|
||||||
public
|
public
|
||||||
{ public declarations }
|
{ public declarations }
|
||||||
|
procedure HandleAccelerometerChanged(Sender: TObject);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -41,6 +45,12 @@ begin
|
|||||||
Hide;
|
Hide;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm2.Button2Click(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Accelerometer.OnSensorChanged := @HandleAccelerometerChanged;
|
||||||
|
Accelerometer.StartReadingAccelerometerData();
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TForm2.Edit1Exit(Sender: TObject);
|
procedure TForm2.Edit1Exit(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
DebugLn('[Edit1Exit]');
|
DebugLn('[Edit1Exit]');
|
||||||
@ -62,5 +72,12 @@ begin
|
|||||||
DebugLn('[Edit1UTF8KeyPress] Char=' + UTF8Key);
|
DebugLn('[Edit1UTF8KeyPress] Char=' + UTF8Key);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm2.HandleAccelerometerChanged(Sender: TObject);
|
||||||
|
begin
|
||||||
|
labelSensorData.Caption := Format('X=%f Y=%f Z=%f', [Accelerometer.xaxis,
|
||||||
|
Accelerometer.yaxis, Accelerometer.zaxis]);
|
||||||
|
DebugLn(labelSensorData.Caption);
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ uses
|
|||||||
customdrawnproc,
|
customdrawnproc,
|
||||||
// LCL
|
// LCL
|
||||||
customdrawn_common, customdrawncontrols, customdrawndrawers,
|
customdrawn_common, customdrawncontrols, customdrawndrawers,
|
||||||
lazcanvas, lazregions,
|
lazcanvas, lazregions, lazdeviceapis,
|
||||||
InterfaceBase,
|
InterfaceBase,
|
||||||
Controls, Forms, lclproc, IntfGraphics, GraphType,
|
Controls, Forms, lclproc, IntfGraphics, GraphType,
|
||||||
LCLType, LMessages, Graphics, LCLStrConsts;
|
LCLType, LMessages, Graphics, LCLStrConsts;
|
||||||
@ -252,6 +252,8 @@ function Java_com_pascal_lclproject_LCLActivity_LCLOnTimer(
|
|||||||
env:PJNIEnv; this:jobject; ATimer: jobject): jint; cdecl;
|
env:PJNIEnv; this:jobject; ATimer: jobject): jint; cdecl;
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged(
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged(
|
||||||
env:PJNIEnv; this:jobject; ANewDPI, ANewWidth: jint): jint; cdecl;
|
env:PJNIEnv; this:jobject; ANewDPI, ANewWidth: jint): jint; cdecl;
|
||||||
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnSensorChanged(
|
||||||
|
env:PJNIEnv; this:jobject; ASensorKind: jint; AValues: JFloatArray): jint; cdecl;
|
||||||
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
|
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
|
||||||
procedure JNI_OnUnload(vm:PJavaVM;reserved:pointer); cdecl;
|
procedure JNI_OnUnload(vm:PJavaVM;reserved:pointer); cdecl;
|
||||||
|
|
||||||
@ -305,6 +307,7 @@ var
|
|||||||
javaMethod_LCLDoDestroyTimer: jmethodid = nil;
|
javaMethod_LCLDoDestroyTimer: jmethodid = nil;
|
||||||
javaMethod_LCLDoHideVirtualKeyboard: jmethodid = nil;
|
javaMethod_LCLDoHideVirtualKeyboard: jmethodid = nil;
|
||||||
javaMethod_LCLDoShowVirtualKeyboard: jmethodid = nil;
|
javaMethod_LCLDoShowVirtualKeyboard: jmethodid = nil;
|
||||||
|
javaMethod_LCLDoStartReadingAccelerometer: jmethodid = nil;
|
||||||
|
|
||||||
// This is utilized to store the information such as invalidate requests in events
|
// This is utilized to store the information such as invalidate requests in events
|
||||||
eventResult: jint;
|
eventResult: jint;
|
||||||
|
@ -163,6 +163,22 @@ begin
|
|||||||
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoHideVirtualKeyboard);
|
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoHideVirtualKeyboard);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCDWidgetSet.LazDeviceAPIs_RequestPositionInfo(AMethod: TLazPositionMethod);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCDWidgetSet.LazDeviceAPIs_SendMessage(AMsg: TLazDeviceMessage);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCDWidgetSet.LazDeviceAPIs_StartReadingAccelerometerData();
|
||||||
|
begin
|
||||||
|
// Call the method
|
||||||
|
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoStartReadingAccelerometer);
|
||||||
|
end;
|
||||||
|
|
||||||
function TCDWidgetSet.PromptUser(const DialogCaption : string;
|
function TCDWidgetSet.PromptUser(const DialogCaption : string;
|
||||||
const DialogMessage : string;
|
const DialogMessage : string;
|
||||||
DialogType : LongInt;
|
DialogType : LongInt;
|
||||||
|
@ -113,6 +113,21 @@ begin
|
|||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCDWidgetSet.LazDeviceAPIs_RequestPositionInfo(AMethod: TLazPositionMethod);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCDWidgetSet.LazDeviceAPIs_SendMessage(AMsg: TLazDeviceMessage);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCDWidgetSet.LazDeviceAPIs_StartReadingAccelerometerData();
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Function: PromptUser
|
Function: PromptUser
|
||||||
Params:
|
Params:
|
||||||
|
@ -114,6 +114,21 @@ begin
|
|||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCDWidgetSet.LazDeviceAPIs_RequestPositionInfo(AMethod: TLazPositionMethod);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCDWidgetSet.LazDeviceAPIs_SendMessage(AMsg: TLazDeviceMessage);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCDWidgetSet.LazDeviceAPIs_StartReadingAccelerometerData();
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Function: PromptUser
|
Function: PromptUser
|
||||||
Params:
|
Params:
|
||||||
|
@ -114,6 +114,21 @@ begin
|
|||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCDWidgetSet.LazDeviceAPIs_RequestPositionInfo(AMethod: TLazPositionMethod);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCDWidgetSet.LazDeviceAPIs_SendMessage(AMsg: TLazDeviceMessage);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCDWidgetSet.LazDeviceAPIs_StartReadingAccelerometerData();
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Function: PromptUser
|
Function: PromptUser
|
||||||
Params:
|
Params:
|
||||||
|
@ -56,6 +56,10 @@ procedure HideVirtualKeyboard();
|
|||||||
(*function IntfSendsUTF8KeyPress: boolean; override;
|
(*function IntfSendsUTF8KeyPress: boolean; override;
|
||||||
function IsDesignerDC(WindowHandle: HWND; DC: HDC): Boolean; override;*)
|
function IsDesignerDC(WindowHandle: HWND; DC: HDC): Boolean; override;*)
|
||||||
|
|
||||||
|
procedure LazDeviceAPIs_RequestPositionInfo(AMethod: TLazPositionMethod); override;
|
||||||
|
procedure LazDeviceAPIs_SendMessage(AMsg: TLazDeviceMessage); override;
|
||||||
|
procedure LazDeviceAPIs_StartReadingAccelerometerData(); override;
|
||||||
|
|
||||||
function PromptUser(const DialogCaption : string;
|
function PromptUser(const DialogCaption : string;
|
||||||
const DialogMessage : string;
|
const DialogMessage : string;
|
||||||
DialogType : LongInt;
|
DialogType : LongInt;
|
||||||
|
@ -250,7 +250,37 @@ begin
|
|||||||
CDWidgetset.DefaultFontAndroidSize := Round(16 * (ANewDPI / 125));
|
CDWidgetset.DefaultFontAndroidSize := Round(16 * (ANewDPI / 125));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
const NativeMethods: array[0..6] of JNINativeMethod=
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnSensorChanged(
|
||||||
|
env:PJNIEnv; this:jobject; ASensorKind: jint; AValues: JFloatArray): jint; cdecl;
|
||||||
|
var
|
||||||
|
arraydata: PSingle;
|
||||||
|
arraylen: jsize;
|
||||||
|
lIsCopy: jboolean;
|
||||||
|
begin
|
||||||
|
Result := 0;
|
||||||
|
|
||||||
|
if (javaEnvRef = nil) then Exit;
|
||||||
|
|
||||||
|
// Get the elements and length
|
||||||
|
lIsCopy := 0;
|
||||||
|
arraylen := javaEnvRef^^.GetArrayLength(javaEnvRef, AValues);
|
||||||
|
arraydata := javaEnvRef^^.GetFloatArrayElements(javaEnvRef, AValues, lIsCopy);
|
||||||
|
|
||||||
|
// Send the data to the LCL
|
||||||
|
if ASensorKind = 1 then
|
||||||
|
begin
|
||||||
|
Accelerometer.xaxis := arraydata[0];
|
||||||
|
Accelerometer.yaxis := arraydata[1];
|
||||||
|
Accelerometer.zaxis := arraydata[2];
|
||||||
|
if Assigned(Accelerometer.OnSensorChanged) then
|
||||||
|
Accelerometer.OnSensorChanged(nil);
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Don't forget to release it
|
||||||
|
javaEnvRef^^.ReleaseFloatArrayElements(javaEnvRef, AValues, arraydata, 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
const NativeMethods: array[0..7] of JNINativeMethod=
|
||||||
((name:'LCLDrawToBitmap';
|
((name:'LCLDrawToBitmap';
|
||||||
signature:'(IILandroid/graphics/Bitmap;)I';
|
signature:'(IILandroid/graphics/Bitmap;)I';
|
||||||
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLDrawToBitmap;),
|
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLDrawToBitmap;),
|
||||||
@ -271,7 +301,10 @@ const NativeMethods: array[0..6] of JNINativeMethod=
|
|||||||
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnTimer;),
|
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnTimer;),
|
||||||
(name:'LCLOnConfigurationChanged';
|
(name:'LCLOnConfigurationChanged';
|
||||||
signature:'(II)I';
|
signature:'(II)I';
|
||||||
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged;)
|
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged;),
|
||||||
|
(name:'LCLOnSensorChanged';
|
||||||
|
signature:'(I[F)I';
|
||||||
|
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnSensorChanged;)
|
||||||
);
|
);
|
||||||
|
|
||||||
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
|
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
|
||||||
@ -358,6 +391,7 @@ begin
|
|||||||
javaMethod_LCLDoDestroyTimer := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoDestroyTimer', '()V');
|
javaMethod_LCLDoDestroyTimer := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoDestroyTimer', '()V');
|
||||||
javaMethod_LCLDoHideVirtualKeyboard := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoHideVirtualKeyboard', '()V');
|
javaMethod_LCLDoHideVirtualKeyboard := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoHideVirtualKeyboard', '()V');
|
||||||
javaMethod_LCLDoShowVirtualKeyboard := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoShowVirtualKeyboard', '()V');
|
javaMethod_LCLDoShowVirtualKeyboard := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoShowVirtualKeyboard', '()V');
|
||||||
|
javaMethod_LCLDoStartReadingAccelerometer := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoStartReadingAccelerometer', '()V');
|
||||||
|
|
||||||
__android_log_write(ANDROID_LOG_INFO, 'lclapp', 'JNI_OnLoad finished');
|
__android_log_write(ANDROID_LOG_INFO, 'lclapp', 'JNI_OnLoad finished');
|
||||||
result:=JNI_VERSION_1_4;// 1_6 is another option
|
result:=JNI_VERSION_1_4;// 1_6 is another option
|
||||||
|
@ -38,10 +38,14 @@ type
|
|||||||
}
|
}
|
||||||
|
|
||||||
TLazAccelerometer = class
|
TLazAccelerometer = class
|
||||||
|
private
|
||||||
|
FOnSensorChanged: TNotifyEvent;
|
||||||
public
|
public
|
||||||
// These fields store the last data read, to get fresh data use UpdateAccelerometerData;
|
// These fields store the last data read, to get fresh data use UpdateAccelerometerData;
|
||||||
xaxis, yaxis, zaxis: Double; // in m/s^2
|
xaxis, yaxis, zaxis: Double; // in m/s^2
|
||||||
procedure StartReadingAccelerometerData();
|
procedure StartReadingAccelerometerData();
|
||||||
|
procedure StopReadingAccelerometerData();
|
||||||
|
property OnSensorChanged: TNotifyEvent read FOnSensorChanged write FOnSensorChanged;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// TLazMessaging
|
// TLazMessaging
|
||||||
@ -100,6 +104,11 @@ begin
|
|||||||
LCLIntf.LazDeviceAPIs_StartReadingAccelerometerData();
|
LCLIntf.LazDeviceAPIs_StartReadingAccelerometerData();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TLazAccelerometer.StopReadingAccelerometerData;
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
{ TLazPositionInfo }
|
{ TLazPositionInfo }
|
||||||
|
|
||||||
procedure TLazPositionInfo.RequestPositionInfo(AMethod: TLazPositionMethod);
|
procedure TLazPositionInfo.RequestPositionInfo(AMethod: TLazPositionMethod);
|
||||||
|
Loading…
Reference in New Issue
Block a user