2015年4月29日 星期三

Remove battery icon in Status bar

環境:4.4.2

由於此版沒有charge ic,所以pmu沒有太大的作用,所以乾脆把系統的statusbar上的battery icon拿掉...
(不知道cts會不會檢查到...)
這次都在 (android_src)/framework/base/ 下

packages/SystemUI/res/layout/status_bar.xml
<!-- battery must be padded below to match assets -->
<com.android.systemui.BatteryMeterView
    android:id="@+id/battery"
    android:layout_height="16dp"
    android:layout_width="10.5dp"
    android:layout_marginBottom="0.33dp"
    android:layout_marginStart="4dip"
/>
應該是透過xml去呼叫BatteryMeterView.java,同時還有定義icon的寬高,把這段註解掉
packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
public void dispatchDemoCommand(String command, Bundle args) 
{
    ...
    if (modeChange || command.equals(COMMAND_BATTERY)) 
    {
        dispatchDemoCommandToView(command, args, R.id.battery);
    }
    if (modeChange || command.equals(COMMAND_STATUS)) 
    {
        if (mDemoStatusIcons == null) 
        {
            mDemoStatusIcons = new DemoStatusIcons(mStatusIcons, mIconSize);
        }
        mDemoStatusIcons.dispatchDemoCommand(command, args);
    }
    ...
}
把這三段 code 也給註解掉
packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarTransitions.java
public void init() 
{
    mLeftSide = mView.findViewById(R.id.notification_icon_area);
    mStatusIcons = mView.findViewById(R.id.statusIcons);
    mSignalCluster = mView.findViewById(R.id.signal_cluster);
    mBattery = mView.findViewById(R.id.battery);
    mClock = mView.findViewById(R.id.clock);
    applyModeBackground(-1, getMode(), false /*animate*/);
    applyMode(getMode(), false /*animate*/);
}
在這有宣告battery id, 所以接著把有用到mBattery的地方給註解就可以了
以上就可以把battery icon給拿掉了,
但如果也想把3G icon給拿掉,好像不能從此下手,要再查查


---------------------------------------------------------------------------------------------
services/java/com/android/server/StatusBarManagerService.java
/** 
  * Construct the service, add the status bar view to the window manager
*/
StatusBarIconList mIcons = new StatusBarIconList();
public StatusBarManagerService(Context context, WindowManagerService windowManager) 
{
    mContext = context;
    mWindowManager = windowManager;
    mWindowManager.setOnHardKeyboardStatusChangeListener(this);
    final Resources res = context.getResources();
    mIcons.defineSlots(res.getStringArray(com.android.internal.R.array.config_statusBarIcons));
}
這裡有個重點:config_statusBarIcons
core/java/com/android/internal/statusbar/StatusBarIconList.java 
private String[] mSlots;
public void defineSlots(String[] slots) 
{
    final int N = slots.length;
    String[] s = mSlots = new String[N];
    for (int i=0; i<N; i++) 
    {
        s[i] = slots[i];
    }
    mIcons = new StatusBarIcon[N];
}
core/res/res/values/config.xml
<string-array name="config_statusBarIcons">  
       ...
       <item><xliff:g id="id">phone_signal</xliff:g></item>  
       <item><xliff:g id="id">battery</xliff:g></item>  
       <item><xliff:g id="id">alarm_clock</xliff:g></item>  
       <item><xliff:g id="id">headset</xliff:g></item>  
       ...
</string-array>
一開始以為把config.xml裡的battery給拿掉,這樣應該就完工了,但還是不行@@

ref : 追求幸福
其它相關的:如果有來生, status_bar.xml超詳细解析Here

沒有留言:

張貼留言