Difference between revisions of "Android Programming/ru"

From Free Pascal wiki
Jump to navigationJump to search
Line 108: Line 108:
 
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.
 
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].
+
Так как существует много устройств на Android, это может быть полезно для отслеживания информации о них. Смотрите также в википедии Comparison of Android Devices [http://en.wikipedia.org/wiki/Comparison_of_Android_devices] и подробную информацию о процессорах в [https://wiki.mozilla.org/Mobile/Platforms/Android#System_Requirements].
  
===Smartphones===
+
===Смартфоны===
  
 
{| BORDER="1" CELLSPACING="0"
 
{| BORDER="1" CELLSPACING="0"
!COLSPAN="1" STYLE="background:#ffdead;"|'''Manufacturer'''
+
!COLSPAN="1" STYLE="background:#ffdead;"|'''Производитель'''
!COLSPAN="1" STYLE="background:#ffdead;"|'''Model'''
+
!COLSPAN="1" STYLE="background:#ffdead;"|'''Модель'''
 
!COLSPAN="1" STYLE="background:#ffdead;"|'''Android API Name (Build.Model)'''
 
!COLSPAN="1" STYLE="background:#ffdead;"|'''Android API Name (Build.Model)'''
!COLSPAN="1" STYLE="background:#ffdead;"|'''Processor'''
+
!COLSPAN="1" STYLE="background:#ffdead;"|'''Процессор'''
!COLSPAN="1" STYLE="background:#ffdead;"|'''Android version'''
+
!COLSPAN="1" STYLE="background:#ffdead;"|'''Версия Андроид'''
 
!COLSPAN="1" STYLE="background:#ffdead;"|'''Multi-touch'''
 
!COLSPAN="1" STYLE="background:#ffdead;"|'''Multi-touch'''
!COLSPAN="1" STYLE="background:#ffdead;"|'''Comments'''
+
!COLSPAN="1" STYLE="background:#ffdead;"|'''Комментарий'''
 
|---
 
|---
|HTC||Wildfire||HTC Wildfire||armv6||2.1=>2.2||Yes||-
+
|HTC||Wildfire||HTC Wildfire||armv6||2.1=>2.2||Да||-
 
|---
 
|---
|Sony Erricson||Xperia X10||X10i||armv7||1.6=>2.1||No||-
+
|Sony Erricson||Xperia X10||X10i||armv7||1.6=>2.1||Нет||-
 
|}
 
|}
  
Line 131: Line 131:
  
 
{| BORDER="1" CELLSPACING="0"
 
{| BORDER="1" CELLSPACING="0"
!COLSPAN="1" STYLE="background:#ffdead;"|'''Manufacturer'''
+
!COLSPAN="1" STYLE="background:#ffdead;"|'''Производитель'''
!COLSPAN="1" STYLE="background:#ffdead;"|'''Model'''
+
!COLSPAN="1" STYLE="background:#ffdead;"|'''Модель'''
 
!COLSPAN="1" STYLE="background:#ffdead;"|'''Android API Name (Build.Model)'''
 
!COLSPAN="1" STYLE="background:#ffdead;"|'''Android API Name (Build.Model)'''
!COLSPAN="1" STYLE="background:#ffdead;"|'''Processor'''
+
!COLSPAN="1" STYLE="background:#ffdead;"|'''Процессор'''
!COLSPAN="1" STYLE="background:#ffdead;"|'''Android version'''
+
!COLSPAN="1" STYLE="background:#ffdead;"|'''Версия Андроид'''
 
!COLSPAN="1" STYLE="background:#ffdead;"|'''Multi-touch'''
 
!COLSPAN="1" STYLE="background:#ffdead;"|'''Multi-touch'''
!COLSPAN="1" STYLE="background:#ffdead;"|'''Comments'''
+
!COLSPAN="1" STYLE="background:#ffdead;"|'''Комментарий'''
 
|---
 
|---
 
|Toshiba||Folio 100 Tablet||TOSHIBA_FOLIO_AND_A||armv7||2.2||Yes||-
 
|Toshiba||Folio 100 Tablet||TOSHIBA_FOLIO_AND_A||armv7||2.2||Yes||-
Line 239: Line 239:
 
*Vodafone 845  
 
*Vodafone 845  
 
*ZTE Blade
 
*ZTE Blade
 +
 +
===Playing Sounds and Videos in the Phones===
 +
 +
Each phone comes with different codecs installed, which will mean that the native Media Player will be able to play different formats in different phones. Bellow is a table showing which formats play in the native Media Player of each phone:
 +
 +
{| BORDER="1" CELLSPACING="0"
 +
!COLSPAN="1" STYLE="background:#ffdead;"|'''Telephone'''
 +
!COLSPAN="1" STYLE="background:#ffdead;"|'''Android'''
 +
!COLSPAN="1" STYLE="background:#ffdead;"|'''webm - VP8'''
 +
!COLSPAN="1" STYLE="background:#ffdead;"|'''m4v - H.264'''
 +
!COLSPAN="1" STYLE="background:#ffdead;"|'''ogv - Theora'''
 +
!COLSPAN="1" STYLE="background:#ffdead;"|'''mp4 - H.264'''
 +
!COLSPAN="1" STYLE="background:#ffdead;"|'''mov - H.264'''
 +
!COLSPAN="1" STYLE="background:#ffdead;"|'''avi - RLE'''
 +
!COLSPAN="1" STYLE="background:#ffdead;"|'''mpg - MPEG-1'''
 +
!COLSPAN="1" STYLE="background:#ffdead;"|'''wmv - WM9'''
 +
!COLSPAN="1" STYLE="background:#ffdead;"|'''3gp - MPEG-4'''
 +
|----
 +
|Emulator||1.6||x||x||x||x||x||x||x||x||OK
 +
|----
 +
|Emulator||2.1||x||x||x||x||x||x||x||x||OK
 +
|----
 +
|Nexus One||2.2||x||OK||x||OK||x||x||x||x||OK
 +
|----
 +
|HTC Desire||1.6||x||OK||x||OK||x||x||x||OK||OK
 +
|----
 +
|Toshiba Folio 100||2.2||x||OK||x||OK||x||x||x||OK||OK
 +
|----
 +
|Xperia X10||2.1||x||OK||x||x||x||x||x||OK||OK
 +
|----
 +
|Xperia X8||2.2||x||OK||x||x||x||x||x||x||OK
 +
|----
 +
|HTC Wildfire||2.1||x||OK||x||x||x||x||x||x||OK
 +
|----
 +
|HTC Desire HD||2.2||x||OK||x||OK||x||x||x||x||OK
 +
|----
 +
|Galaxy Tab||2.2||x||OK||x||x||x||x||x||x||OK
 +
|----
 +
|myPhone A210||1.6||x||OK||x||x||x||x||x||x||OK
 +
|----
 +
|Motorola Milestone||2.1||x||OK||x||x||x||x||x||OK||?
 +
|----
 +
|Milestone 2||2.2||x||OK||x||x||x||x||x||sound-only||OK
 +
|}
  
 
==Creating a new Java Android Application==
 
==Creating a new Java Android Application==

Revision as of 13:46, 6 February 2012

English (en) 日本語 (ja) 한국어 (ko) русский (ru) 中文(中国大陆)‎ (zh_CN)

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

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

Как...

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

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

Шаг 1 - Скачайте и установите Android NDK, Android SDK и Ant. Боьше информации тут: Android_Interface/Using_the_Android_SDK,_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,_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.

Подробная информация об устройствах с Андроид

Так как существует много устройств на Android, это может быть полезно для отслеживания информации о них. Смотрите также в википедии Comparison of Android Devices [1] и подробную информацию о процессорах в [2].

Смартфоны

Производитель Модель Android API Name (Build.Model) Процессор Версия Андроид Multi-touch Комментарий
HTC Wildfire HTC Wildfire armv6 2.1=>2.2 Да -
Sony Erricson Xperia X10 X10i armv7 1.6=>2.1 Нет -

Tablets

Производитель Модель Android API Name (Build.Model) Процессор Версия Андроид Multi-touch Комментарий
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:

  • Advent Vega (P10AN01)
  • Dell Streak, Streak 7
  • HTC Desire
  • HTC Desire Z (T-Mobile G2)
  • HTC Desire HD
  • HTC Droid Incredible
  • HTC EVO 4G, EVO Shift 4G
  • HTC Glacier (T-Mobile myTouch 4G)
  • HTC Inspire 4G
  • HTC Nexus One
  • HTC Thunderbolt 4G
  • Huawei Ideos S7
  • LG Optimus Z
  • Motorola Atrix 4G
  • Motorola Bravo
  • Motorola Cliq 2 - untested
  • Motorola Defy
  • Motorola Droid 2, Droid 2 Global
  • Motorola Droid Pro (Motorola PRO)
  • Motorola Droid X
  • Motorola Xoom
  • POV Mobii Tegra Tablet
  • Samsung Continuum (i400)
  • Samsung Galaxy S (i9000, Captivate, Fascinate, Vibrant, Epic 4G)
  • Samsung Galaxy Tab
  • Sharp IS03
  • Sony Ericsson Xperia X10
  • Toshiba AS100
  • Viewsonic gTablet
  • Acer Liquid E
  • Acer Liquid (Liquid A1)
  • Archos 101 Internet Tablet
  • Motorola Charm
  • Motorola Droid (Milestone)
  • Samsung Galaxy S 4G
  • Samsung Nexus S

List of ARMv6 processors:

  • Android SDK emulator
  • Asus Garmin nuvifone A50 (T-Mobile Garminfone)
  • Augen GENTouch 78 Tablet
  • Coby Kyros Internet Tablet (MID7015)
  • Geeksphone One, Geeksphone Zero
  • HTC Aria
  • HTC ChaCha
  • HTC Dream (T-Mobile G1, Android Dev Phone 1)
  • HTC Droid Eris
  • HTC Espresso (T-Mobile myTouch 3G Slide)
  • HTC Hero (T-Mobile G2 Touch)
  • HTC Legend
  • HTC Magic (T-Mobile myTouch 3G, T-Mobile G1 Touch)
  • HTC Salsa
  • HTC Tattoo
  • HTC Wildfire
  • Huawei Ascend
  • Huawei Ideos U8150-B (T-Mobile Comet)
  • Huawei U8110 (T-Mobile Pulse Mini)
  • Huawei U8230
  • LG Ally (Apex) (LG VS740)
  • LG GW620 (Eve, InTouch Max, LinkMe)
  • LG Optimus, Optimus M, Optimus T, Optimus S, Optimus V
  • LG Vortex
  • LG P500
  • MAG iMiTO iM7
  • vMAG iMiTO iM7S
  • Motorola Backflip
  • Motorola Citrus
  • Motorola Cliq (MB200)
  • Motorola Dext
  • Motorola Devour
  • Motorola i1
  • Motorola Spice XT300
  • Motorola Quench XT5 XT502
  • Pandigital Novel
  • Samsung GT-S5570 Galaxy Mini
  • Samsung i5500 Galaxy 5 (Corby)
  • Samsung i5700 Galaxy Portal (Spica)
  • Samsung i5800 Galaxy 3
  • Samsung i7500 Galaxy
  • Samsung Intercept
  • Samsung M900 Moment
  • Samsung S5830 Galaxy Ace
  • Samsung Transform
  • Sanyo ZIO M6000
  • Sony Ericsson Xperia X8
  • Sony Ericsson Xperia X10 Mini
  • Sony Ericsson Xperia X10 Mini Pro
  • Superpad 10.2" Tablet PC
  • Viewsonic ViewPad 7 Tablet
  • Velocity Micro T103 Cruz tablet
  • Vodafone 845
  • ZTE Blade

Playing Sounds and Videos in the Phones

Each phone comes with different codecs installed, which will mean that the native Media Player will be able to play different formats in different phones. Bellow is a table showing which formats play in the native Media Player of each phone:

Telephone Android webm - VP8 m4v - H.264 ogv - Theora mp4 - H.264 mov - H.264 avi - RLE mpg - MPEG-1 wmv - WM9 3gp - MPEG-4
Emulator 1.6 x x x x x x x x OK
Emulator 2.1 x x x x x x x x OK
Nexus One 2.2 x OK x OK x x x x OK
HTC Desire 1.6 x OK x OK x x x OK OK
Toshiba Folio 100 2.2 x OK x OK x x x OK OK
Xperia X10 2.1 x OK x x x x x OK OK
Xperia X8 2.2 x OK x x x x x x OK
HTC Wildfire 2.1 x OK x x x x x x OK
HTC Desire HD 2.2 x OK x OK x x x x OK
Galaxy Tab 2.2 x OK x x x x x x OK
myPhone A210 1.6 x OK x x x x x x OK
Motorola Milestone 2.1 x OK x x x x x OK ?
Milestone 2 2.2 x OK x x x x x sound-only OK

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