Jump to content

vfbb

Members
  • Content Count

    266
  • Joined

  • Last visited

  • Days Won

    30

Everything posted by vfbb

  1. @Fabian1648 The adaptive icon is the way to have your icon full quality in all devices of all manufacturers. You did something wrong during the steps as it works on a blank project (you can test). Remembering that in some versions of android it is necessary to uninstall the old application for the icon to be updated. Also, on some androids (like LG's Android 10) when you click beyond uninstall, the android only disables the application, so you must go to Settings > Applications, and uninstall. Please provide more information, print the deployment and the manifest and the print also, after a Run, the generated files in the output folder, example: (project)\Android64\Release\(project)\res
  2. Adaptive Icon First of all, don’t uncheck the icons in deployment and don’t change the manifest. 1) Add your icons in .png format in Project Options normally. This is necessary to keep the compatibility with android 7.1 and oldest. 2) You need to create 3 files "ic_launcher.xml", "ic_launcher_background.xml" and "ic_launcher_foreground.xml" 3) ic_launcher.xml example: <?xml version="1.0" encoding="utf-8"?> <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> <background android:drawable="@drawable/ic_launcher_background" /> <foreground android:drawable="@drawable/ic_launcher_foreground" /> </adaptive-icon> Add it in deployment with remote path "res\drawable-anydpi-v26" 4) ic_background.xml example: <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="108dp" android:height="108dp" android:viewportWidth="108.0" android:viewportHeight="108.0"> <path android:name="square" android:fillColor="#ff3657f4" android:pathData="M0,0 L108,0 L108,108 L0,108 z" /> </vector> Note that I fixed a solid color (#ff3657f4), but you can put gradients in this xml or an image in place the background (not recomended). Add it in deployment with remote path "res\drawable" 5) ic_foreground.xml example: <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="108dp" android:height="108dp" android:viewportWidth="108.0" android:viewportHeight="108.0"> <path android:name="square" android:fillColor="#ffffffff" android:pathData="M 53.91,32.73 C 54.35,32.75 54.49,33.06 54.75,33.39 54.75,33.39 56.18,35.17 56.18,35.17 56.18,35.17 62.30,42.80 62.30,42.80 62.30,42.80 65.32,46.57 65.32,46.57 67.71,49.56 69.15,51.35 69.99,55.19 70.19,56.06 70.35,56.97 70.35,57.86 70.35,60.63 70.34,61.92 69.39,64.60 67.61,69.60 63.19,73.48 58.06,74.76 56.05,75.26 54.85,75.23 52.81,75.20 51.89,75.19 50.64,74.92 49.74,74.70 44.14,73.29 39.76,68.84 38.20,63.31 37.95,62.41 37.66,60.97 37.65,60.04 37.62,57.15 37.69,55.37 38.79,52.61 39.86,49.91 41.15,48.49 42.92,46.27 42.92,46.27 48.17,39.73 48.17,39.73 48.17,39.73 51.98,34.98 51.98,34.98 52.41,34.44 53.40,33.04 53.91,32.73 Z M 46.57,58.86 C 46.57,58.86 43.70,58.86 43.70,58.86 43.70,58.86 43.70,59.45 43.70,59.45 43.70,63.37 46.54,66.93 50.04,68.42 50.88,68.79 51.80,69.02 52.71,69.13 53.27,69.20 53.36,69.10 54.00,69.26 54.00,69.26 54.00,66.29 54.00,66.29 52.87,66.29 51.97,66.13 50.93,65.66 48.53,64.57 46.57,61.94 46.57,59.25 46.57,59.25 46.57,58.86 46.57,58.86 Z" /> </vector> You can change the white color (#ffffffff) and the pathData. Note: this pathData is the same path data inside the .svg. If you have your icon in .svg, just open it in notepad and copy the "d" field inside the "path" to the pathData of xml (only if the svg has size 108x108). Add it in deployment with remote path "res\drawable" Result (the low quality is due to the gif format) Extra You can do the same with the splash screen (vector splash screen). The vector splash screen works in all android versions supported by Delphi.
  3. There are really few apps on Windows, except for chat apps, which fully support unicode (including MS apps), but in my case I really need to deal with this because it will be just a cross platform chat (Win, Android, iOS). Today's problem is to fix TEdit, but it is not just that, but the safe way to manipulate any string received from the user. It is the same as using AnsiString/AnsiChar when the input is string (unicode), you are at risk of generating an unexpected string. To clarify the problem, follow an example on TEdit: 1) Select a TEdit, press Windows key +. to open the emoji window 2) Select for example the "White man raising his hand" which is represented by 7 characters, that is, 14 bytes) 3) Proceed: Example string manipulation: In a string manipulation it is very common, for example, to take x first characters, so suppose I want to take the first 8 chars: S := S.Substring(0, 8); But if S is "🙋🏻‍♂️🙋🏻‍♂️", which incredibly has 14 chars, and which is the same as: S := #55357 + #56907 + #55356 + #57339 + #8205 + #9794 + #65039 + #55357 + #56907 + #55356 + #57339 + #8205 + #9794 + #65039; When I give the substring (0, 8), the result will be: S := #55357 + #56907 + #55356 + #57339 + #8205 + #9794 + #65039 + #55357; Which is represented by: 🙋🏻‍♂️� But a Substring (1, 7) would be even worse in this case: The problem is very clear and a modern application, mainly of chat, has to know how to deal with it.
  4. Wrong! Actually porting the C# code will be laborious and will require maintenance as the unicode is changed. The best solution at this point is to use apis: Windows - DWriteTextAnalyze Android - GraphemeCharsLength := JString.codePointAt(Index); iOS - CFStringGetRangeOfComposedCharactersAtIndex
  5. All manipulations of strings received by user input should consider each element and not each individual character. This is basically why delphi TEdit does not work properly with these kind of emojis (just try adding one and pressing backspace that you will see part of problem). In short, when you don't consider this, you risk breaking a string into a position in the middle of a Grapheme, creating a malformed string. As I said, this iteration is essential, Embarcadero should implement this natively to work cross-platform just like C # did. The best thing to do at this point is to port the C # code.
  6. Embarcadero should create a class based on C# TextElementEnumerator, which does exactly this.
  7. Apparently simple, but in practice nothing trivial, and with nothing on the internet about this, I decided to do a brief tutorial to master the Android system bars. https://github.com/viniciusfbb/fmx_tutorials/tree/master/delphi_android_system_bars/
  8. vfbb

    Delphi Rio 10.3.2 : iOS Custom Font

    Just a tip: it is not mandatory to place the .ttf file in the project folder, you can put it in a subfolder then add that subfolder in "Search path"
  9. vfbb

    Waiting for multiple threads

    This problem is very common because without proper care the threads end in a different order than the units. The rule to avoid this is: each unit that creates each thread has to guarantee that the thread it created will be canceled and completely terminated until the finalization of the unit. How to do this? There are several possibilities, I will quote one: 1) Create a way to cancel each thread (it is almost always possible through a simple Boolean + TEvent.SetEvent, but each case must be evaluated) 2) Create a unique TEvent to signal the end of the thread; Just run the thread code in a try finaly FFinishEvent.SetEvent; 3) At the end of the unit, cancel the thread, and give FFinishEvent.WaitFor;
  10. Have you tried to see if there are any more exception or information debugging the IDE? Open some bpl then Run> Parameters... > Host Application "C:\Program Files (x86)\Embarcadero\Studio\21.0\bin\bds.exe" > Save > press F9 Then new instance of delphi will be created in debug mode, then you can reproduce the error in that delphi instance and you may have more information about the problem.
  11. vfbb

    iOS push notification http/2

    You can use Firebase Cloud Messaging instead. There are some examples of FCM with delphi in github.
  12. vfbb

    Nneed a mentor

    It was a pleasure to help you 😉
  13. vfbb

    Android 11 Support in 10.4.2?

    I'm not going to talk about delphi 10.4.2 because I still have 10.4.1. But on sdk, you don't need to use this Embarcadero tool, it is almost always a version behind. Ideally, you should install Android Studio on your own, open it and Configure> SDK Manager and install (download) the latest sdk, get the directory and configure it in your Delphi Options > Deployment > SDK Manager> Android
  14. Sometimes I come across some delphi language enhancements that are undocumented or are poorly documented. In the last few years docwiki has improved a lot, but there are still undocumented cases, such as accessing an item in an array just by declaring a property, without any method: TipGeolocation = record private FCoordinates: array[0..1] of Double; public property Latitude: Double read FCoordinates[0] write FCoordinates[0]; property Longitude: Double read FCoordinates[1] write FCoordinates[1]; end; Share here any enhancements to the delphi language that you have discovered but are not documented.
  15. Virtual interfaces: to create an object that support an interface in run time. See System.Rtti.TVirtualInterface
  16. Although I don't particularly like this design, you can make a descendant of TInterfacedPersistent, your class will not be arc and will be able to implement interfaces. TBaseFrame = class(TInterfacedPersistent)
  17. Making it available to everyone who want a thread safe, asynchronous, cross-platform and simplistic messaging system for communication between classes / layers in delphi applications. https://github.com/viniciusfbb/ipub-messaging
  18. A very simple way to consume one Rest Api, just declaring one interface, based on .Net Refit: https://github.com/viniciusfbb/ipub-refit
  19. vfbb

    iPub Refit - REST API in simple way

    @Attila Kovacs You are right about compatibility, thanks for checking this out. I will put this observation. In the future I can do some backwards compatibility, but not now. About the null values serialization, this library is just to consumes one rest api, then the serialization can occur just when you call a Post or Put and have the parameter ABody that is a record or a class or an array. In this specific case, the library will serialize the type as json, and in this case, the values that is null will be written to the json body without skip. The current implementation of System.JSON.Serializers don’t permit to ignore the fields with null values. Sorry i'll make it clearer
  20. vfbb

    iPub Refit - REST API in simple way

    @Attila Kovacs Here one example without TValue.Make<T>, and with the nullables stating with IsNull True: uses System.Rtti, System.TypInfo, System.JSON.Serializers, System.JSON.Readers, System.JSON.Writers, System.JSON.Types, iPub.Rtl.Refit; type TNullable<T> = record strict private FIsNotNull: Boolean; function GetIsNull: Boolean; procedure SetIsNull(AValue: Boolean); public Value: T; property IsNull: Boolean read GetIsNull write SetIsNull; end; TNullableConverter<T> = class(TJsonConverter) public procedure WriteJson(const AWriter: TJsonWriter; const AValue: TValue; const ASerializer: TJsonSerializer); override; function ReadJson(const AReader: TJsonReader; ATypeInf: PTypeInfo; const AExistingValue: TValue; const ASerializer: TJsonSerializer): TValue; override; function CanConvert(ATypeInf: PTypeInfo): Boolean; override; end; { TNullable<T> } function TNullable<T>.GetIsNull: Boolean; begin Result := not FIsNotNull; end; procedure TNullable<T>.SetIsNull(AValue: Boolean); begin FIsNotNull := not AValue; end; { TNullableConverter<T> } function TNullableConverter<T>.CanConvert(ATypeInf: PTypeInfo): Boolean; begin Result := ATypeInf = TypeInfo(TNullable<T>); end; function TNullableConverter<T>.ReadJson(const AReader: TJsonReader; ATypeInf: PTypeInfo; const AExistingValue: TValue; const ASerializer: TJsonSerializer): TValue; var LNullable: TNullable<T>; begin if AReader.TokenType = TJsonToken.Null then begin LNullable.IsNull := True; LNullable.Value := Default(T); end else begin LNullable.IsNull := False; LNullable.Value := AReader.Value.AsType<T>; end; TValue.Make(@LNullable, TypeInfo(TNullable<T>), Result); end; procedure TNullableConverter<T>.WriteJson(const AWriter: TJsonWriter; const AValue: TValue; const ASerializer: TJsonSerializer); var LNullable: TNullable<T>; LValue: TValue; begin LNullable := AValue.AsType<TNullable<T>>; if LNullable.IsNull then AWriter.WriteNull else begin TValue.Make(@LNullable.Value, TypeInfo(T), LValue); AWriter.WriteValue(LValue); end; end; initialization GRestService.RegisterConverters([TNullableConverter<string>, TNullableConverter<Byte>, TNullableConverter<Word>, TNullableConverter<Integer>, TNullableConverter<Cardinal>, TNullableConverter<Single>, TNullableConverter<Double>, TNullableConverter<Int64>, TNullableConverter<UInt64>, TNullableConverter<TDateTime>, TNullableConverter<Boolean>, TNullableConverter<Char>]); end. To test: TUser = record Name: TNullable<string>; Location: string; Id: Integer; Email: TNullable<string>; NonexistentField: TNullable<Integer>; end; [BaseUrl('https://api.github.com')] IGithubApi = interface(IipRestApi) ['{4C3B546F-216D-46D9-8E7D-0009C0771064}'] [Get('/users/{user}')] function GetUser(const AUser: string): TUser; end; procedure TForm1.FormCreate(Sender: TObject); var LGithubApi: IGithubApi; LUser: TUser; begin LGithubApi := GRestService.&For<IGithubApi>; LUser := LGithubApi.GetUser('viniciusfbb'); end;
  21. vfbb

    iPub Refit - REST API in simple way

    Works perfectly in both cases, with the [] or with {..},{..},{..}. In both cases your function result should be a TArray<> of a record or a class. Do you mean what happens with the nullable fields that were not received? Well, all fields are set to the default value before reading the received json, so there are several possible workarounds to ensure that the field not received is considered null. In sydney just add the class operator Initialize to set IsNull true, but in older versions, you can simply change the name of IsNull to IsValid, since the boolean fields started False, then the initial value of IsValid of nullable will be False. But there are other possibilities.
  22. vfbb

    iPub Refit - REST API in simple way

    @Attila Kovacs About the version of delphi supported, according to docwiki, the units System.JSON.XXX was introduced in Delphi 10 Seattle, but again I can’t guarantee it’s compatible as it would need to be tested on these versions.
  23. vfbb

    iPub Refit - REST API in simple way

    @Attila Kovacs I added support to register custom json converters. About the nullables, is very easy to implement the nullable and the converters. See one simple solution: uses System.Rtti, System.TypInfo, System.JSON.Serializers, System.JSON.Readers, System.JSON.Writers, System.JSON.Types, iPub.Rtl.Refit; type TNullable<T> = record IsNull: Boolean; Value: T; end; TNullableConverter<T> = class(TJsonConverter) public procedure WriteJson(const AWriter: TJsonWriter; const AValue: TValue; const ASerializer: TJsonSerializer); override; function ReadJson(const AReader: TJsonReader; ATypeInf: PTypeInfo; const AExistingValue: TValue; const ASerializer: TJsonSerializer): TValue; override; function CanConvert(ATypeInf: PTypeInfo): Boolean; override; end; { TNullableConverter<T> } function TNullableConverter<T>.CanConvert(ATypeInf: PTypeInfo): Boolean; begin Result := ATypeInf = TypeInfo(TNullable<T>); end; function TNullableConverter<T>.ReadJson(const AReader: TJsonReader; ATypeInf: PTypeInfo; const AExistingValue: TValue; const ASerializer: TJsonSerializer): TValue; var LNullable: TNullable<T>; begin if AReader.TokenType = TJsonToken.Null then begin LNullable.IsNull := True; LNullable.Value := Default(T); end else begin LNullable.IsNull := False; LNullable.Value := AReader.Value.AsType<T>; end; TValue.Make<TNullable<T>>(LNullable, Result); end; procedure TNullableConverter<T>.WriteJson(const AWriter: TJsonWriter; const AValue: TValue; const ASerializer: TJsonSerializer); var LNullable: TNullable<T>; LValue: TValue; begin LNullable := AValue.AsType<TNullable<T>>; if LNullable.IsNull then AWriter.WriteNull else begin TValue.Make<T>(LNullable.Value, LValue); AWriter.WriteValue(LValue); end; end; initialization GRestService.RegisterConverters([TNullableConverter<string>, TNullableConverter<Byte>, TNullableConverter<Word>, TNullableConverter<Integer>, TNullableConverter<Cardinal>, TNullableConverter<Single>, TNullableConverter<Double>, TNullableConverter<Int64>, TNullableConverter<UInt64>, TNullableConverter<TDateTime>, TNullableConverter<Boolean>, TNullableConverter<Char>]); end. To use just replace the simple types to the nullable types: TUser = record Name: TNullable<string>; Location: string; Id: Integer; Email: TNullable<string>; end; [BaseUrl('https://api.github.com')] IGithubApi = interface(IipRestApi) ['{4C3B546F-216D-46D9-8E7D-0009C0771064}'] [Get('/users/{user}')] function GetUser(const AUser: string): TUser; end; procedure TForm1.FormCreate(Sender: TObject); var LGithubApi: IGithubApi; LUser: TUser; begin LGithubApi := GRestService.&For<IGithubApi>; LUser := LGithubApi.GetUser('viniciusfbb'); end; You can test the code above and see the user name is not null but the user email is null. The nullable type and the nullable converter code in this example need to be implemented by the developer, I can't put it on the library because each developer has it own implementation os nullable.
  24. vfbb

    iPub Refit - REST API in simple way

    I don't have older versions installed to be able to test, or do backwards compatibility, but it looks like you're right, delphi 10.2 tokyo or newer. What exactly did you want? The json serialization of delphi is very malleable, you do not need to declare all the necessary fields and you can also use all existing attributes in System.Json.Serializers.pas. It's a great option, I will implement it today.
  25. vfbb

    Cross-platform messaging system

    Made. It's not worth, it's a very limited system, synchronous, windows support only ...
×