Difference between revisions of "Android Programming/ru"

From Lazarus wiki
Jump to navigationJump to search
(New page: ==How to...== ===Build the NDK OpenGL example=== Just follow these steps: '''Step 1''' - Download and install the Android NDK, Android SDK and Ant. More information here: [[Android_Inte...)
Line 1: Line 1:
==How to...==
===Build the NDK OpenGL example===
Just follow these steps:
'''Step 1''' - Download and install the Android NDK, Android SDK and Ant. More information here: [[Android_Interface/Using_the_Android_SDK%2C_Emulator_and_Phones]]
'''Step 2''' - Install the pre-compiled FPC cross-compiler. Instructions here: [[Android_Interface#Using_the_pre-compiled_compiler]]
'''Step 3''' - Download the latest lazarus-ccr sourceforge code:
svn co https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr lazarus-ccr
or if you think it is too big you can download just the folder lazarus-ccr/bindings/android-ndk
'''Step 4''' - Building the Pascal Library
Open the project lazarus-ccr/bindings/android-ndk/examples/opengltest/opengltest.lpi
Go to Project->Project Options->Paths and where is written "Libraries -Fl" you should see this value:
Change it to the correct path in your system which points to the NDK and to the library folder for your minimal required Android API Level
Now build the project using Lazarus.
'''Step 5''' - Configuring the build environment
Open the file opengltest/local.properties and in this line:
Change this to point to your SDK location
'''Step 6''' - Buildings the APK
Open a terminal and type these commands:
cd lazarus-ccr/bindings/ndk/examples/opengltest/android
ant debug
The APK file will be placed in opengltest/android/bin/
'''Step 7''' - Install the APK
In this step if you get error messages about permissions read: [[Android_Interface/Using_the_Android_SDK%2C_Emulator_and_Phones#Recognition_of_devices_under_Linux]]
The command to install our APK in the phone is:
cd opengltest/android
~/Programas/android-sdk-linux/platform-tools/adb install bin/OpenGLNDKTest-debug.apk
2395 KB/s (107299 bytes in 0.043s)
        pkg: /data/local/tmp/OpenGLNDKTest-debug.apk
If you get an error message that it is already installed you can install with this command:
~/Programas/android-sdk-linux/platform-tools/adb uninstall com.pascal.opengltest
And then you can run adb logcat to see what the log says while you start it in the phone via its newly added icon:
~/Programas/android-sdk-linux/platform-tools/adb logcat
===Read the screen metrics===
First fill a TDisplayMetrics with the correct info:
uses androidutil;
  MyDisplayMetrics: TDisplayMetrics;
  Str: string;
  lHeight, lWidth: Integer;
  xdpi, ydpi, lScreenSize: Single;
  // ..
  // Objects
  MyDisplayMetrics := TDisplayMetrics.Create;
And then you can read it from the TDisplayMetrics:
  lHeight := MyDisplayMetrics.heightPixels();
  lWidth := MyDisplayMetrics.widthPixels();
  xdpi := MyDisplayMetrics.xdpi();
  ydpi := MyDisplayMetrics.ydpi();
  lScreenSize := sqrt(sqr(lHeight / ydpi) + sqr(lWidth / xdpi));
  ldensity := MyDisplayMetrics.density();
  ldensityDpi := MyDisplayMetrics.densityDpi();
  scaledDensity := MyDisplayMetrics.scaledDensity();
Note that lots of devices lie about the xdpi and ydpi, so don't trust the lScreenSize calculated above. Smartphones might report even 10 inches of screen size, while the correct is around 4.

Revision as of 07:33, 6 February 2012