您的位置:首页 > 移动开发 > Android开发

Android 4.0 虚拟按键、手机模式、平板模式

2013-05-24 14:56 337 查看
关键词:android 4.0 手机模式(phone) 平板模式(table) 虚拟按键 lcd_density
平台信息:

内核:linux2.6/linux3.0

系统:android/android4.0

平台:S5PV310(samsungexynos4210/4412)

三星新拿回来来的BSP,编译后没有“返回、最近打开应用、home”三个虚拟键。我们硬件在设计的时候也没有设定相应的物理按键,平时调试程序的时候比较麻烦。怎么把这三个按键显示出来??下面我们来说明。

同时在开始分析问前我引入另外两个问题:

table 模式、phone模式选择;

lcd_density参数设定,来决定图标密度大小。

一、引入问题:

1、 手机模式、平板模式

android4.0手机模式、平板模式两种情况 界面的主体布局不太一样,如下图所示。





2、lcd_density

ro.sf.lcd_density=240 和ro.sf.lcd_density=160两种不同的现象,很明显说明这个参数的做用。后面我们遇到一个问题要从这里说明。



[html]
view plaincopyprint?

To change the density of the screen change /system/build.prop ro.sf.lcd_density=240 high-density, at the right of the picture, comes by default in the mephisto's roms. ro.sf.lcd_density=180 low density, at the left of the picture (This means that the number of pixels per inch is 240=800/3.5" 3.5" is the screen of the H1 and 800×480 display resolution). So you can pick any number between 240 and 180 - personally I use 220. You can do this using root explorer apk for instance:
To change the density of the screen change /system/build.prop
ro.sf.lcd_density=240
high-density, at the right of the picture, comes by default in the mephisto's roms.
ro.sf.lcd_density=180
low density, at the left of the picture
(This means that the number of pixels per inch is 240=800/3.5"
3.5" is the screen of the H1 and 800×480 display resolution).
So you can pick any number between 240 and 180 - personally I use 220.
You can do this using root explorer apk for instance:


二、问题分析

1、参考网友的说法:

将\frameworks\base\core\res\res\values\config.xml中的下面属性的值改为true;

[html]
view plaincopyprint?

<bool name="config_showNavigationBar">false</bool>

<bool name="config_showNavigationBar">false</bool>

状态:

[html]
view plaincopyprint?

模式:phone 参数:config_showNavigationBar=true
模式:phone
参数:config_showNavigationBar=true



出现以下情况:

(1)、虚拟按键边上那个黑框已经出来;

(2)、看不到三个按键图标;

(3)、点击边缘时会有颜色变化,横屏是“返回”键,竖屏时点击为“最近打开程序”;感觉那个按键被放大了一样。 由上面分析,这种现象是布局出问题,我们LCD分辨率为1280*800,其实三个按键出来了,只不过图标显示太大,所以我们看不到。同时在这里我们引入前面我们提到的两个问题:(1)、table
模式、phone模式选择;(2)lcd_density参数设定,来决定图标密度大小。
很明显的我们可以看出现在编译的时phone模式、那个图标为什么看不到, lcd­_density设定的图标太大。

2、问题分析

打开机器,在串口终端或者是adb shell中:

cd/system

catdefault.prop



我们可以看到:

[html]
view plaincopyprint?

ro.build.characteristics=phone

ro.build.characteristics=phone


这就是我们所说的table、phone参数设定,不同的模式在这里决定的。查找这些参数在那里设定,最终找到:
android_ramos_4412_02/android/device/samsung/smdk4x12/device.mk

[html]
view plaincopyprint?

ifeq ($(BOARD_USES_HIGH_RESOLUTION_LCD),true) //(1)、如果满足条件,就设为table模式;
PRODUCT_CHARACTERISTICS := tablet
PRODUCT_COPY_FILES += \ frameworks/base/data/etc/tablet_core_hardware.xml:system/etc/permissions/tablet_core_hardware.xml
$(call inherit-product, frameworks/base/build/tablet-dalvik-heap.mk)
else
PRODUCT_CHARACTERISTICS := phone //(2)、满足条件就设为phone模式;
PRODUCT_COPY_FILES += \
frameworks/base/data/etc/handheld_core_hardware.xml:system/etc/permissions/handheld_core_hardware.xml
$(call inherit-product, frameworks/base/build/phone-hdpi-512-dalvik-heap.mk) PRODUCT_PROPERTY_OVERRIDES += \
ro.sf.lcd_density=240 //(3)、lcd_density设定。
PRODUCT_AAPT_CONFIG := normal hdpi
Endif

ifeq ($(BOARD_USES_HIGH_RESOLUTION_LCD),true) //(1)、如果满足条件,就设为table模式;
PRODUCT_CHARACTERISTICS := tablet
PRODUCT_COPY_FILES += \ frameworks/base/data/etc/tablet_core_hardware.xml:system/etc/permissions/tablet_core_hardware.xml
$(call inherit-product, frameworks/base/build/tablet-dalvik-heap.mk)
else
PRODUCT_CHARACTERISTICS := phone //(2)、满足条件就设为phone模式;
PRODUCT_COPY_FILES += \
frameworks/base/data/etc/handheld_core_hardware.xml:system/etc/permissions/handheld_core_hardware.xml
$(call inherit-product, frameworks/base/build/phone-hdpi-512-dalvik-heap.mk) PRODUCT_PROPERTY_OVERRIDES += \
ro.sf.lcd_density=240                //(3)、lcd_density设定。
PRODUCT_AAPT_CONFIG := normal hdpi
Endif


(1)、如果满足条件,就设为table

BOARD_USES_HIGH_RESOLUTION_LCD = true,就设定为table模式。

(2)、满足条件就设为phone模式;

BOARD_USES_HIGH_RESOLUTION_LCD = flash,就设定为phone模式

(3)、lcd_density设定。

在PRODUCT_CHARACTERISTICS := phone时,lcd_density设置为240。
现在我们要用table模式,所以我们要把BOARD_USES_HIGH_RESOLUTION_LCD这个参数设定为true。

android_ramos_4412_02/android/device/samsung/smdk4x12/BoardConfig.mk

[html]
view plaincopyprint?

OARD_USES_HIGH_RESOLUTION_LCD := true

OARD_USES_HIGH_RESOLUTION_LCD := true


把BOARD_USES_HIGH_RESOLUTION_LCD选为ture就可以编译成平板模式。

(4)、把config_showNavigationBar还原成默认值

将\frameworks\base\core\res\res\values\config.xml

[html]
view plaincopyprint?

<boolnameboolname="config_showNavigationBar">false</bool>

<boolname="config_showNavigationBar">false</bool>


状态

[html]
view plaincopyprint?

模式:table 参数:config_showNavigationBar=false

模式:table
参数:config_showNavigationBar=false


编译,平板模式三个虚拟按键就可以出来了。我们的问题解决了。设为平板模式;三个虚拟按键出现。

三、phone模式下为什么只有一个黑框?

问题解决了,但是我们还有一个疑问,那就是按网友那种方法改动后,为什么没有出现我们理想的效果呢?回顾“1、参考网友的说法:”更改后,个别键有做用,但是不能看到三个按键。

分析代码android/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

[html]
view plaincopyprint?

mNavigationBarHeight =mHasNavigationBar ? mContext.getResources().getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height) : 0; mNavigationBarWidth =mHasNavigationBar ?mContext.getResources().getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width) : 0;
Log.v(TAG, "xubin testmNavigationBarHeight = " + mNavigationBarHeight
 " mNavigationBarWidth =" +mNavigationBarWidth);

mNavigationBarHeight =mHasNavigationBar ? mContext.getResources().getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height) : 0; mNavigationBarWidth =mHasNavigationBar ?mContext.getResources().getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width) : 0;
Log.v(TAG, "xubin testmNavigationBarHeight = " + mNavigationBarHeight
  " mNavigationBarWidth =" +mNavigationBarWidth);


[html]
view plaincopyprint?

<SPAN style="FONT-FAMILY: Arial, Helvetica, sans-serif; WHITE-SPACE: normal">打印值为:</SPAN>

打印值为:


[html]
view plaincopyprint?

V/WindowManager( 1250): xubin testmNavigationBarHeight = 72 mNavigationBarWidth =63 V/WindowManager(1250): xubin test mNavigationBarHeight = 72 mNavigationBarWidth =63

V/WindowManager( 1250): xubin testmNavigationBarHeight = 72 mNavigationBarWidth =63
V/WindowManager(1250): xubin test mNavigationBarHeight = 72 mNavigationBarWidth =63


打印出来的信息也没什么问题,相对的而已文件也正确。这就回到我们开始提到那个lcd_density参数问题了,上面可以很明显的看到,当lcd_density值发生小的改变后,图标大小有很大的变化,再个来说我们LCD的分辨率太高,1280X800的,所以把那三人图标放大大,所以我们看到上面那种现象。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: