平臺信息:
內核: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兩種不同的現象,很明顯說明這個參數的做用。後面我們遇到一個問題要從這裏說明。
- 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;
- <bool name="config_showNavigationBar">false</bool>
<bool name="config_showNavigationBar">false</bool>
狀態:
- 模式: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
我們可以看到:
- ro.build.characteristics=phone
ro.build.characteristics=phone
這就是我們所說的table、phone參數設定,不同的模式在這裏決定的。查找這些參數在那裏設定,最終找到:
android_ramos_4412_02/android/device/samsung/smdk4x12/device.mk
- 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
- 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
- <boolnameboolname="config_showNavigationBar">false</bool>
<boolname="config_showNavigationBar">false</bool>
狀態
- 模式:table
- 參數:config_showNavigationBar=false
模式:table
參數:config_showNavigationBar=false
編譯,平板模式三個虛擬按鍵就可以出來了。我們的問題解決了。設爲平板模式;三個虛擬按鍵出現。
三、phone模式下爲什麼只有一個黑框?
問題解決了,但是我們還有一個疑問,那就是按網友那種方法改動後,爲什麼沒有出現我們理想的效果呢?回顧“1、參考網友的說法:”更改後,個別鍵有做用,但是不能看到三個按鍵。
分析代碼android/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
- 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);
- <SPAN style="FONT-FAMILY: Arial, Helvetica, sans-serif; WHITE-SPACE: normal">打印值爲:</SPAN>
打印值爲:
- 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的,所以把那三人圖標放大大,所以我們看到上面那種現象。