unit MyDeviceInfo;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Devices,
FMX.BehaviorManager, System.Math, FMX.
Platform, FMX.MultiView;
type
TMyDeviceInfo =
class(TCustomMultiView)
private
FDeviceService: IFMXDeviceService;
function DefineContext: TFmxObject;
function GetDevice: TDeviceInfo;
public
class function isPhoneMode(form:TForm; myFormatSettings:TFormatSettings):boolean;
end;
implementation
uses MyLog;
function TMyDeviceInfo.DefineContext: TFmxObject;
begin
if Owner
is TFmxObject
then
Result := TFmxObject(Owner)
else
Result := Parent;
end;
function TMyDeviceInfo.GetDevice: TDeviceInfo;
var
DeviceService: IDeviceBehavior;
Context: TFmxObject;
begin
if csDesigning
in ComponentState
then
begin
Context := DefineContext;
if TBehaviorServices.Current.SupportsBehaviorService(IDeviceBehavior,DeviceService, Context)
then
Exit(DeviceService.GetDevice(Context));
end;
Result := TDeviceInfo.ThisDevice;
end;
class function TMyDeviceInfo.isPhoneMode(form:TForm; myFormatSettings:TFormatSettings):boolean;
var FMyCustomMV : TMyDeviceInfo;
ThisDevice: TDeviceInfo;
logStr:
String;
begin
try
FMyCustomMV := TMyDeviceInfo.Create(form);
TPlatformServices.Current.SupportsPlatformService(IFMXDeviceService,FMyCustomMV.FDeviceService);
ThisDevice := FMyCustomMV.GetDevice;
case ThisDevice.DeviceClass
of
TDeviceInfo.TDeviceClass.Phone:
begin
logStr:='
Phone ';
Result:=true;
end;
TDeviceInfo.TDeviceClass.Tablet:
begin
logStr:='
Tablet ';
Result:=false;
end;
TDeviceInfo.TDeviceClass.Desktop:
begin
logStr:='
Desktop ';
Result:=false;
end
else begin
logStr:='
Unknown ';
Result:=true;
end;
end;
if (FMyCustomMV.GetOrientation
in [TScreenOrientation.Landscape, TScreenOrientation.InvertedLandscape])
then
logStr:=logStr+'
(landscape) '
else
logStr:=logStr+'
(portrait) ';
{logStr:=logStr+CurrToStrF(ThisDevice.MinPhysicalScreenSize.Width,ffNumber,1,myFormatSettings)+' ';
logStr:=logStr+CurrToStrF(ThisDevice.MinPhysicalScreenSize.Height,ffNumber,1,myFormatSettings)+' ';
logStr:=logStr+CurrToStrF(ThisDevice.MaxPhysicalScreenSize.Width,ffNumber,1,myFormatSettings)+' ';
logStr:=logStr+CurrToStrF(ThisDevice.MaxPhysicalScreenSize.Height,ffNumber,1,myFormatSettings)+' ';
logStr:=logStr+IntToStr(ThisDevice.PixelsPerInch)+' ';
logStr:=logStr+CurrToStrF(ThisDevice.MaxDiagonal*2.54,ffNumber,1,myFormatSettings)+'cm';}
//mlog.info('Display: '+logStr);
except on E:
Exception do
begin
Result:=false;
//mlog.error('Can´t determine phone mode: '+e.message);
end;
end;
end;
end.