Android Programming/ru

This is an old revision of Android Programming/ru, edited by Kverde at . The current revision is 78220.

/* Построить пример NDK (Android Native Development Kit) OpenGL */

Смотрите также Custom Drawn Interface/Android

Общие знания о программировании под Андроид могут очень помочь в разработке интерфейса Lazarus для Андроид.

Как...

Построить NDK (Android Native Development Kit) OpenGL

Просто выполните следующие действия:

Шаг 1 - Скачайте и установите Android NDK, Android SDK и Ant. Боьше информации тут: Android_Interface/Using_the_Android_SDK%2C_Emulator_and_Phones

Шаг 2 - Установите pre-compiled FPC cross-compiler. Инстрцкции здесь: Android_Interface#Using_the_pre-compiled_compiler

Шаг 3 - Загрузите последнюю версию lazarus-ccr sourceforge code:

svn co https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr lazarus-ccr

или если вы думаете что это слишком много, вы можете скачать только каталог lazarus-ccr/bindings/android-ndk

Шаг 4 - Постройте Pascal Library

Откройте проект lazarus-ccr/bindings/android-ndk/examples/opengltest/opengltest.lpi

Откройте пункт меню Project->Project Options->Paths и где написано "Libraries -Fl" вы должны увидеть следующее значение:

/home/felipe/Programas/android-ndk-r5/platforms/android-9/arch-arm/usr/lib

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

Теперь постройте проект используя Лазарус.

Шаг 5 - Настройка среды сборки

Откройте файл opengltest/local.properties и в строке:

sdk.dir=/home/felipe/Programas/android-sdk-linux

Измените этот путь на местоположение SDK

Шаг 6 - Постройка APK

Откройте консоль и введите следущие команды:

cd lazarus-ccr/bindings/ndk/examples/opengltest/android ant debug

Файл APK будет помещен в opengltest/android/bin/

Шаг 7 - Установка APK

Если на этом шаге вы получите сообщение об ошибке прав доступа читайте: Android_Interface/Using_the_Android_SDK%2C_Emulator_and_Phones#Recognition_of_devices_under_Linux

Команда чтобы установить APK на телефоне:

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
Success

Если вы получили сообщение об ошибке, что APK уже установлен, вы можете установить с помощью следующей команды:

~/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

Чтение параметров экрана

First fill a TDisplayMetrics with the correct info:

<delphi> uses androidutil;

var

 MyDisplayMetrics: TDisplayMetrics;
 Str: string;
 //
 lHeight, lWidth: Integer;
 xdpi, ydpi, lScreenSize: Single;

begin

 // ..
 // Objects
 MyDisplayMetrics := TDisplayMetrics.Create;
 Activity.getWindowManager().getDefaultDisplay().getMetrics(MyDisplayMetrics);

</delphi>

And then you can read it from the TDisplayMetrics:

<delphi>

 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();

</delphi>

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.

Details about Android devices

Since there are so many Android devices, it can be useful to keep track of some information about them. See also in the wikipedia Comparison of Android Devices http://en.wikipedia.org/wiki/Comparison_of_Android_devices and details about the processors in https://wiki.mozilla.org/Mobile/Platforms/Android#System_Requirements.

Smartphones

Manufacturer Model Android API Name (Build.Model) Processor Android version Multi-touch Comments
HTC Wildfire HTC Wildfire armv6 2.1=>2.2 Yes -
Sony Erricson Xperia X10 X10i armv7 1.6=>2.1 No -

Tablets

Manufacturer Model Android API Name (Build.Model) Processor Android version Multi-touch Comments
Toshiba Folio 100 Tablet TOSHIBA_FOLIO_AND_A armv7 2.2 Yes -

List of devices ordered by processor compatibility (ARMv6 vs ARMv7)

List of ARMv7 devices:

List of ARMv6 processors:

Creating a new Java Android Application

This info can be useful for helping implement LCL-CustomDrawn-Android

Generic instructions here: http://developer.android.com/guide/developing/other-ide.html

Showing / Hiding the virtual keyboard

See here: http://android-codes-examples.blogspot.com/2011/11/show-or-hide-soft-keyboard-on-opening.html

To show it:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

and for hiding the keyboard:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(singleedittext.getWindowToken(),0);

References