Difference between revisions of "Android Interface/Native Android GUI"

From Lazarus wiki
Jump to navigationJump to search
m (Reverted edits by Reverse22 (Talk); changed back to last version by Penilopa P)
m (Text replace - "delphi>" to "syntaxhighlight>")
Line 38: Line 38:
 
====Timer example====
 
====Timer example====
  
<delphi>
+
<syntaxhighlight>
 
program turbochessclock4android;
 
program turbochessclock4android;
  
Line 76: Line 76:
 
   // ...
 
   // ...
 
end.
 
end.
</delphi>
+
</syntaxhighlight>

Revision as of 14:49, 24 March 2012

Go back to Android Interface

Android4Pascal

See the page about Android4Pascal, which is the bindings between Pascal programs and the Android Java APIs.


Manifest configuration

Control the program restart

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:

 <activity
    ...
    android:configChanges="orientation|keyboardHidden"

See also:

Resource files

Guidelines for the Icons

Read here: http://developer.android.com/guide/practices/ui_guidelines/icon_design.html

Using other APIs

Using the Timer

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.

Timer example

program turbochessclock4android;

{$mode objfpc}{$H+}

uses
  Classes, SysUtils, androidpipescomm, androidview, javalang,
  androidapp, androidtimer;//, gles11;

type
  TEventHandler = class
  public
    procedure HandleOnTimer(ASender: TObject);
    procedure buttonClickCallback(v: TView);
  end;

var
  //...
  TimerCount: Integer = 0;
  MyTimer: TAndroidTimer;
  MyEventHandler: TEventHandler;

procedure TEventHandler.buttonClickCallback(v: TView);
begin
  MyTimer.postDelayed(100);
end;

procedure TEventHandler.HandleOnTimer(ASender: TObject);
begin
  Inc(TimerCount);
  tv.setText(Format('Timer event #%d', [TimerCount]));
  MyTimer.postDelayed(1000);
end;

begin
  MyEventHandler := TEventHandler.Create;
  // ...
end.