Skip to content

Commit

Permalink
Merge pull request #15 from DeveloppeurPascal/master
Browse files Browse the repository at this point in the history
added Delphi 11 Alexandria compatibility
  • Loading branch information
adrianosantostreina authored Oct 2, 2021
2 parents fc35ee3 + 468b227 commit 9bbd442
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 32 deletions.
73 changes: 60 additions & 13 deletions Package/MobilePermissions.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<ProjectGuid>{1777638F-CDB4-4A84-9CD9-2A399D7E84A5}</ProjectGuid>
<MainSource>MobilePermissions.dpk</MainSource>
<ProjectVersion>19.1</ProjectVersion>
<ProjectVersion>19.2</ProjectVersion>
<FrameworkType>FMX</FrameworkType>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
Expand Down Expand Up @@ -33,11 +33,21 @@
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='OSX64' and '$(Base)'=='true') or '$(Base_OSX64)'!=''">
<Base_OSX64>true</Base_OSX64>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
<Base_Win32>true</Base_Win32>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Base)'=='true') or '$(Base_Win64)'!=''">
<Base_Win64>true</Base_Win64>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_1)'!=''">
<Cfg_1>true</Cfg_1>
<CfgParent>Base</CfgParent>
Expand Down Expand Up @@ -103,6 +113,7 @@
<DCC_DcpOutput>$(BDSCOMMONDIR)\Bpl</DCC_DcpOutput>
<DCC_BplOutput>$(BDSCOMMONDIR)\Bpl</DCC_BplOutput>
<VerInfo_Build>1</VerInfo_Build>
<Android_LauncherIcon192>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_192x192.png</Android_LauncherIcon192>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Android64)'!=''">
<VerInfo_Keys>package=com.embarcadero.$(MSBuildProjectName);label=$(MSBuildProjectName);versionCode=1;versionName=1.0.0;persistent=False;restoreAnyVersion=False;installLocation=auto;largeHeap=False;theme=TitleBar;hardwareAccelerated=true;apiKey=</VerInfo_Keys>
Expand All @@ -116,15 +127,21 @@
<VerInfo_Build>1</VerInfo_Build>
<DCC_DcpOutput>$(BDSCOMMONDIR)\Bpl</DCC_DcpOutput>
<DCC_BplOutput>$(BDSCOMMONDIR)\Bpl</DCC_BplOutput>
<Android_LauncherIcon192>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_192x192.png</Android_LauncherIcon192>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_iOSDevice64)'!=''">
<DCC_CBuilderOutput>None</DCC_CBuilderOutput>
<DCC_UsePackage>rtl;fmx;$(DCC_UsePackage)</DCC_UsePackage>
<iOS_AppStore1024>$(BDS)\bin\Artwork\iOS\iPhone\FM_ApplicationIcon_1024x1024.png</iOS_AppStore1024>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_iOSSimulator)'!=''">
<DCC_CBuilderOutput>None</DCC_CBuilderOutput>
<DCC_UsePackage>rtl;fmx;$(DCC_UsePackage)</DCC_UsePackage>
<VerInfo_Keys>CFBundleName=$(MSBuildProjectName);CFBundleDevelopmentRegion=fr;CFBundleDisplayName=$(MSBuildProjectName);CFBundleIdentifier=$(MSBuildProjectName);CFBundleInfoDictionaryVersion=7.1;CFBundleVersion=1.0.0;CFBundleShortVersionString=1.0.0;CFBundlePackageType=APPL;CFBundleSignature=????;LSRequiresIPhoneOS=true;CFBundleAllowMixedLocalizations=YES;CFBundleExecutable=$(MSBuildProjectName);UIDeviceFamily=iPhone &amp; iPad;NSLocationAlwaysUsageDescription=The reason for accessing the location information of the user;NSLocationWhenInUseUsageDescription=The reason for accessing the location information of the user;NSLocationAlwaysAndWhenInUseUsageDescription=The reason for accessing the location information of the user;UIBackgroundModes=;NSContactsUsageDescription=The reason for accessing the contacts;NSPhotoLibraryUsageDescription=The reason for accessing the photo library;NSPhotoLibraryAddUsageDescription=The reason for adding to the photo library;NSCameraUsageDescription=The reason for accessing the camera;NSFaceIDUsageDescription=The reason for accessing the face id;NSMicrophoneUsageDescription=The reason for accessing the microphone;NSSiriUsageDescription=The reason for accessing Siri;ITSAppUsesNonExemptEncryption=false;NSBluetoothAlwaysUsageDescription=The reason for accessing bluetooth;NSBluetoothPeripheralUsageDescription=The reason for accessing bluetooth peripherals;NSCalendarsUsageDescription=The reason for accessing the calendar data;NSRemindersUsageDescription=The reason for accessing the reminders;NSMotionUsageDescription=The reason for accessing the accelerometer;NSSpeechRecognitionUsageDescription=The reason for requesting to send user data to Apple&apos;s speech recognition servers</VerInfo_Keys>
<VerInfo_UIDeviceFamily>iPhoneAndiPad</VerInfo_UIDeviceFamily>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_OSX64)'!=''">
<VerInfo_Keys>CFBundleName=$(MSBuildProjectName);CFBundleDisplayName=$(MSBuildProjectName);CFBundleIdentifier=$(MSBuildProjectName);CFBundleVersion=1.0.0;CFBundleShortVersionString=1.0.0;CFBundlePackageType=APPL;CFBundleSignature=????;CFBundleAllowMixedLocalizations=YES;CFBundleExecutable=$(MSBuildProjectName);NSHighResolutionCapable=true;LSApplicationCategoryType=public.app-category.utilities;NSLocationUsageDescription=The reason for accessing the location information of the user;NSContactsUsageDescription=The reason for accessing the contacts;NSCalendarsUsageDescription=The reason for accessing the calendar data;NSRemindersUsageDescription=The reason for accessing the reminders;NSCameraUsageDescription=The reason for accessing the camera;NSMicrophoneUsageDescription=The reason for accessing the microphone;NSMotionUsageDescription=The reason for accessing the accelerometer;NSDesktopFolderUsageDescription=The reason for accessing the Desktop folder;NSDocumentsFolderUsageDescription=The reason for accessing the Documents folder;NSDownloadsFolderUsageDescription=The reason for accessing the Downloads folder;NSNetworkVolumesUsageDescription=The reason for accessing files on a network volume;NSRemovableVolumesUsageDescription=The reason for accessing files on a removable volume;NSSpeechRecognitionUsageDescription=The reason for requesting to send user data to Apple&apos;s speech recognition servers</VerInfo_Keys>
<BT_BuildType>Debug</BT_BuildType>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win32)'!=''">
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
Expand All @@ -135,6 +152,12 @@
<DCC_DcpOutput>$(BDSCOMMONDIR)\Bpl</DCC_DcpOutput>
<DCC_BplOutput>$(BDSCOMMONDIR)\Bpl</DCC_BplOutput>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win64)'!=''">
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)</DCC_Namespace>
<BT_BuildType>Debug</BT_BuildType>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Locale>1033</VerInfo_Locale>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''">
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
<DCC_DebugDCUs>true</DCC_DebugDCUs>
Expand Down Expand Up @@ -231,19 +254,14 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="$(BDS)\Redist\osx64\libcgsqlite3.dylib" Class="DependencyModule">
<Platform Name="OSX64">
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="c:\program files (x86)\embarcadero\studio\20.0\lib\Win32\Debug\MobilePermissions.bpl" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>MobilePermissions.bpl</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="$(BDS)\Redist\iossimulator\libcgunwind.1.0.dylib" Class="DependencyModule">
<Platform Name="iOSSimulator">
<DeployFile LocalName="$(BDS)\Redist\osx64\libcgsqlite3.dylib" Class="DependencyModule">
<Platform Name="OSX64">
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
Expand All @@ -252,6 +270,11 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="$(BDS)\Redist\iossimulator\libcgunwind.1.0.dylib" Class="DependencyModule">
<Platform Name="iOSSimulator">
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="$(BDS)\Redist\osx32\libcgsqlite3.dylib" Class="DependencyModule">
<Platform Name="OSX32">
<Overwrite>true</Overwrite>
Expand All @@ -271,6 +294,16 @@
<Operation>0</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidClasses">
<Platform Name="Android">
<RemoteDir>classes</RemoteDir>
<Operation>64</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>classes</RemoteDir>
<Operation>64</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidClassesDexFile">
<Platform Name="Android">
<RemoteDir>classes</RemoteDir>
Expand Down Expand Up @@ -399,6 +432,16 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_LauncherIcon192">
<Platform Name="Android">
<RemoteDir>res\drawable-xxxhdpi</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-xxxhdpi</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_LauncherIcon36">
<Platform Name="Android">
<RemoteDir>res\drawable-ldpi</RemoteDir>
Expand Down Expand Up @@ -1244,14 +1287,15 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Linux64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="OSXARM64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Linux64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="OSX32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="OSX64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="iOSSimulator" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Android64" Name="$(PROJECTNAME)"/>
</Deployment>
Expand All @@ -1260,7 +1304,10 @@
<Platform value="Android64">True</Platform>
<Platform value="iOSDevice64">False</Platform>
<Platform value="iOSSimulator">False</Platform>
<Platform value="Linux64">False</Platform>
<Platform value="OSX64">False</Platform>
<Platform value="Win32">True</Platform>
<Platform value="Win64">False</Platform>
</Platforms>
</BorlandProject>
<ProjectFileVersion>12</ProjectFileVersion>
Expand Down
63 changes: 44 additions & 19 deletions Source/MobilePermissions.Permissions.Android.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,50 @@
interface

uses
{$IF CompilerVersion >= 33.0}
{$IF CompilerVersion >= 33.0}
// Delphi 10.3 Rio
System.Permissions,
{$ENDIF}
{$IFDEF ANDROID}
{$ENDIF}
{$IF CompilerVersion >= 35.0}
// Delphi 11 Alexandria
System.Types,
{$ENDIF}
{$IFDEF ANDROID}
Androidapi.Helpers,
Androidapi.JNI.Os,
Androidapi.JNI.JavaTypes,
FMX.Dialogs,
{$ENDIF}
{$ENDIF}
System.Character,
System.Classes,
System.SysUtils,
System.StrUtils,
MobilePermissions.Permissions.Base,
MobilePermissions.Permissions.Interfaces;

type TMobilePermissionsAndroid = class(TMobilePermissionsBase, IMobilePermissions)
type
TMobilePermissionsAndroid = class(TMobilePermissionsBase, IMobilePermissions)
private
FAndroidVersion : Integer;
FAndroidVersion: Integer;

procedure SetAndroidVersion;

procedure RequestPermissionsResultProc(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>);
{$IF CompilerVersion >= 35.0}
// after Delphi 11 Alexandria
procedure RequestPermissionsResultProc(const APermissions
: TClassicStringDynArray;
const AGrantResults: TClassicPermissionStatusDynArray);
{$ELSE}
// before Delphi 11 Alexandria
procedure RequestPermissionsResultProc(const APermissions: TArray<string>;
const AGrantResults: TArray<TPermissionStatus>);
{$ENDIF}
public
function Request(Permissions: TArray<string>): IMobilePermissions; override;

constructor create;
destructor Destroy; override;
end;
destructor Destroy; override;
end;

implementation

Expand All @@ -50,14 +65,14 @@ destructor TMobilePermissionsAndroid.Destroy;
procedure TMobilePermissionsAndroid.SetAndroidVersion;
{$IFDEF ANDROID}
var
VersionOSStr : String;
MajorVersion : string;
I : Integer;
VersionOSStr: String;
MajorVersion: string;
I: Integer;
{$ENDIF}
begin
if FAndroidVersion = 0 then
begin
{$IFDEF ANDROID}
{$IFDEF ANDROID}
VersionOSStr := JStringToString(TJBuild_VERSION.JavaClass.RELEASE);

for I := 1 to VersionOSStr.Length do
Expand All @@ -68,21 +83,31 @@ procedure TMobilePermissionsAndroid.SetAndroidVersion;
MajorVersion := MajorVersion + Copy(VersionOSStr, I, 1);
end;
FAndroidVersion := StrToInt(MajorVersion);
{$ENDIF}
{$ENDIF}
end;
end;

function TMobilePermissionsAndroid.Request(Permissions: TArray<string>): IMobilePermissions;
function TMobilePermissionsAndroid.Request(Permissions: TArray<string>)
: IMobilePermissions;
begin
result := Self;
SetAndroidVersion;
{$IF CompilerVersion >= 33.0}
{$IF CompilerVersion >= 33.0}
if (FAndroidVersion > 6) then
PermissionsService.RequestPermissions(Permissions, RequestPermissionsResultProc, nil);
{$ENDIF}
PermissionsService.RequestPermissions(Permissions,
RequestPermissionsResultProc, nil);
{$ENDIF}
end;

procedure TMobilePermissionsAndroid.RequestPermissionsResultProc(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>);
{$IF CompilerVersion >= 35.0}
procedure TMobilePermissionsAndroid.RequestPermissionsResultProc
(const APermissions: TClassicStringDynArray;
const AGrantResults: TClassicPermissionStatusDynArray);
{$ELSE}
procedure TMobilePermissionsAndroid.RequestPermissionsResultProc(
const APermissions: TArray<string>;
const AGrantResults: TArray<TPermissionStatus>);
{$ENDIF}
begin
if Assigned(FOnRequest) then
FOnRequest(nil);
Expand Down

0 comments on commit 9bbd442

Please # to comment.