Android Interface/Native Android GUI: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Android Interface/Native Android GUI
| Old | New | Line | |
|---|---|---|---|
| 1 | + | *(Android only)* | |
| 2 | + | ||
| 3 | + | Go back to [[Android Interface]] | |
| 4 | + | ||
| 5 | + | ## Android4Pascal | |
| 6 | + | ||
| 7 | + | See the page about [[Android4Pascal]], which is the bindings between Pascal programs and the Android Java APIs. | |
| 8 | + | ||
| 9 | + | ## Manifest configuration | |
| 10 | + | ||
| 11 | + | ### Control the program restart | |
| 12 | + | ||
| 13 | + | By default the program will restart on orientation change, on keyboard change, and in a lot of other cases. This is usually unwanted. To disable program restart on keyboard showing and orientation changed add this to the manifest file: | |
| 14 | + | ||
| 15 | + | ``` pascal | |
| 16 | + | <activity | |
| 17 | + | ... | |
| 18 | + | android:configChanges="orientation|keyboardHidden" | |
| 19 | + | ``` | |
| 20 | + | ||
| 21 | + | See also: | |
| 22 | + | ||
| 23 | + | - <http://developer.android.com/guide/topics/manifest/activity-element.html#config> | |
| 24 | + | ||
| 25 | + | ## Resource files | |
| 26 | + | ||
| 27 | + | ### Guidelines for the Icons | |
| 28 | + | ||
| 29 | + | Read here: <http://developer.android.com/guide/practices/ui_guidelines/icon_design.html> | |
| 30 | + | ||
| 31 | + | ## Using other APIs | |
| 32 | + | ||
| 33 | + | ### Using the Timer | |
| 34 | + | ||
| 35 | + | The Android API bindings include a handy timer control called TAndroidTimer. It works just like a Runnable, and inside it a Handler class is utilized to run the Runnable in the main GUI thread so that event executed in this timer can call Android APIs. | |
| 36 | + | ||
| 37 | + | #### Timer example | |
| 38 | + | ||
| 39 | + | ``` pascal | |
| 40 | + | program turbochessclock4android; | |
| 41 | + | ||
| 42 | + | {$mode objfpc}{$H+} | |
| 43 | + | ||
| 44 | + | uses | |
| 45 | + | Classes, SysUtils, androidpipescomm, androidview, javalang, | |
| 46 | + | androidapp, androidtimer;//, gles11; | |
| 47 | + | ||
| 48 | + | type | |
| 49 | + | TEventHandler = class | |
| 50 | + | public | |
| 51 | + | procedure HandleOnTimer(ASender: TObject); | |
| 52 | + | procedure buttonClickCallback(v: TView); | |
| 53 | + | end; | |
| 54 | + | ||
| 55 | + | var | |
| 56 | + | //... | |
| 57 | + | TimerCount: Integer = 0; | |
| 58 | + | MyTimer: TAndroidTimer; | |
| 59 | + | MyEventHandler: TEventHandler; | |
| 60 | + | ||
| 61 | + | procedure TEventHandler.buttonClickCallback(v: TView); | |
| 62 | + | begin | |
| 63 | + | MyTimer.postDelayed(100); | |
| 64 | + | end; | |
| 65 | + | ||
| 66 | + | procedure TEventHandler.HandleOnTimer(ASender: TObject); | |
| 67 | + | begin | |
| 68 | + | Inc(TimerCount); | |
| 69 | + | tv.setText(Format('Timer event #%d', [TimerCount])); | |
| 70 | + | MyTimer.postDelayed(1000); | |
| 71 | + | end; | |
| 72 | + | ||
| 73 | + | begin | |
| 74 | + | MyEventHandler := TEventHandler.Create; | |
| 75 | + | // ... | |
| 76 | + | end. | |
| 77 | + | ``` | |
| 78 | + | ||
| 79 | + | --- | |
| 80 | + | *From the Free Pascal wiki, page "Android Interface/Native Android GUI", as it stood on 2020-02-09 after a change by GAN, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 81 | + | Category: Android |
