mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 02:39:15 +02:00
LazDeviceAPIs: Adds an API to read the screen orientation
git-svn-id: trunk@40797 -
This commit is contained in:
parent
c48f864fc6
commit
ca38c244cf
@ -55,6 +55,7 @@ type
|
|||||||
// TLazDevice
|
// TLazDevice
|
||||||
class function GetDeviceManufacturer: string; override;
|
class function GetDeviceManufacturer: string; override;
|
||||||
class function GetDeviceModel: string; override;
|
class function GetDeviceModel: string; override;
|
||||||
|
class function GetScreenRotation(AScreenIndex: Integer): TScreenRotation; override;
|
||||||
class procedure Vibrate(ADurationMS: Cardinal); override;
|
class procedure Vibrate(ADurationMS: Cardinal); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -179,6 +180,55 @@ begin
|
|||||||
javaEnvRef^^.ReleaseStringUTFChars(javaEnvRef, lJavaString, lNativeString);
|
javaEnvRef^^.ReleaseStringUTFChars(javaEnvRef, lJavaString, lNativeString);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function TCDWSLazDeviceAPIs.GetScreenRotation(AScreenIndex: Integer
|
||||||
|
): TScreenRotation;
|
||||||
|
var
|
||||||
|
windowManagerClass, displayClass : jclass;
|
||||||
|
javaMethodId_WindowService, javaMethodId_getDefaultDisplay, javaMethodId_getRotation : JMethodID;
|
||||||
|
windowManagerObject, displayObject: JObject;
|
||||||
|
javaString_WINDOW_SERVICE, javaString_getDefaultDisplay : JString;
|
||||||
|
lRotation: Jint;
|
||||||
|
const
|
||||||
|
ROTATION_0 = 0;
|
||||||
|
ROTATION_180 = 2;
|
||||||
|
ROTATION_270 = 3;
|
||||||
|
ROTATION_90 = 1;
|
||||||
|
begin
|
||||||
|
windowManagerClass := javaEnvRef^^.FindClass(javaEnvRef, 'android/view/WindowManager');
|
||||||
|
displayClass := javaEnvRef^^.FindClass(javaEnvRef, 'android/view/Display');
|
||||||
|
|
||||||
|
// get the string Context.WINDOW_SERVICE remember that NewStringUTF does not require ReleaseStringUTFChars
|
||||||
|
javaString_WINDOW_SERVICE := javaEnvRef^^.NewStringUTF(javaEnvRef, pchar('getWindowManager'));
|
||||||
|
|
||||||
|
// get method id for WindowManager object
|
||||||
|
javaMethodId_WindowService := javaEnvRef^^.GetMethodID(javaEnvRef, javaAndroidAppActivityClass, 'getWindowManager', '()Landroid/view/WindowManager;');
|
||||||
|
|
||||||
|
// Get the WindowManager object
|
||||||
|
// Window w = (Window) getSystemService(Context.WINDOW_SERVICE);
|
||||||
|
windowManagerObject := javaEnvRef^^.CallObjectMethod(javaEnvRef, javaActivityObject, javaMethodId_WindowService);
|
||||||
|
|
||||||
|
javaString_getDefaultDisplay := javaEnvRef^^.NewStringUTF(javaEnvRef, pchar('getDefaultDisplay'));
|
||||||
|
|
||||||
|
// Get method id for Display object
|
||||||
|
javaMethodId_getDefaultDisplay := javaEnvRef^^.GetMethodID(javaEnvRef, windowManagerClass, 'getDefaultDisplay', '()Landroid/view/Display;');
|
||||||
|
|
||||||
|
// Get the display object
|
||||||
|
displayObject := javaEnvRef^^.CallObjectMethod(javaEnvRef, windowManagerObject, javaMethodId_getDefaultDisplay);
|
||||||
|
|
||||||
|
// Get method id for method: getRotation
|
||||||
|
javaMethodId_getRotation := javaEnvRef^^.GetMethodID(javaEnvRef, displayClass, 'getRotation', '()I');
|
||||||
|
|
||||||
|
// Now call getRotation method in the display object
|
||||||
|
lRotation := javaEnvRef^^.CallIntMethod(javaEnvRef, displayObject, javaMethodId_getRotation);
|
||||||
|
case lRotation of
|
||||||
|
ROTATION_180: Result := srRotation_180;
|
||||||
|
ROTATION_270: Result := srRotation_270;
|
||||||
|
ROTATION_90: Result := srRotation_90;
|
||||||
|
else
|
||||||
|
Result := srRotation_0;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
class procedure TCDWSLazDeviceAPIs.Vibrate(ADurationMS: Cardinal);
|
class procedure TCDWSLazDeviceAPIs.Vibrate(ADurationMS: Cardinal);
|
||||||
var
|
var
|
||||||
lVibratorObject: JObject;
|
lVibratorObject: JObject;
|
||||||
|
@ -126,12 +126,15 @@ type
|
|||||||
|
|
||||||
// TLazDevice
|
// TLazDevice
|
||||||
|
|
||||||
|
TScreenRotation = (srRotation_0, srRotation_90, srRotation_180, srRotation_270);
|
||||||
|
|
||||||
TLazDevice = class
|
TLazDevice = class
|
||||||
private
|
private
|
||||||
function GetDeviceManufacturer: string;
|
function GetDeviceManufacturer: string;
|
||||||
function GetDeviceModel: string;
|
function GetDeviceModel: string;
|
||||||
public
|
public
|
||||||
procedure Vibrate(ADurationMS: Cardinal);
|
procedure Vibrate(ADurationMS: Cardinal);
|
||||||
|
function GetScreenRotation(AScreenIndex: Integer): TScreenRotation;
|
||||||
property Manufacturer: string read GetDeviceManufacturer;
|
property Manufacturer: string read GetDeviceManufacturer;
|
||||||
property Model: string read GetDeviceModel;
|
property Model: string read GetDeviceModel;
|
||||||
end;
|
end;
|
||||||
@ -172,6 +175,14 @@ begin
|
|||||||
WidgetsetClass.Vibrate(ADurationMS);
|
WidgetsetClass.Vibrate(ADurationMS);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TLazDevice.GetScreenRotation(AScreenIndex: Integer): TScreenRotation;
|
||||||
|
var
|
||||||
|
WidgetsetClass: TWSLazDeviceAPIsClass;
|
||||||
|
begin
|
||||||
|
WidgetsetClass := TWSLazDeviceAPIsClass(GetWSLazDeviceAPIs());
|
||||||
|
Result := WidgetsetClass.GetScreenRotation(AScreenIndex);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TLazAccelerometer }
|
{ TLazAccelerometer }
|
||||||
|
|
||||||
procedure TLazAccelerometer.StartReadingAccelerometerData;
|
procedure TLazAccelerometer.StartReadingAccelerometerData;
|
||||||
|
@ -63,6 +63,7 @@ type
|
|||||||
// TLazDevice
|
// TLazDevice
|
||||||
class function GetDeviceManufacturer: string; virtual;
|
class function GetDeviceManufacturer: string; virtual;
|
||||||
class function GetDeviceModel: string; virtual;
|
class function GetDeviceModel: string; virtual;
|
||||||
|
class function GetScreenRotation(AScreenIndex: Integer): TScreenRotation; virtual;
|
||||||
class procedure Vibrate(ADurationMS: Cardinal); virtual;
|
class procedure Vibrate(ADurationMS: Cardinal); virtual;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -118,6 +119,12 @@ begin
|
|||||||
Result := '';
|
Result := '';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function TWSLazDeviceAPIs.GetScreenRotation(AScreenIndex: Integer
|
||||||
|
): TScreenRotation;
|
||||||
|
begin
|
||||||
|
Result := srRotation_0;
|
||||||
|
end;
|
||||||
|
|
||||||
class procedure TWSLazDeviceAPIs.Vibrate(ADurationMS: Cardinal);
|
class procedure TWSLazDeviceAPIs.Vibrate(ADurationMS: Cardinal);
|
||||||
begin
|
begin
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user