Android 10 SystemUI 如何添加4G信号和WiFi图标

代码路径:
frameworks/base/packages/SystemUI/res/layout/system_icons.xml
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragment.java
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarMobileView.java
frameworks/base/packages/SystemUI/res/layout/status_bar_mobile_signal_group.xml
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarWifiView.java
frameworks/base/packages/SystemUI/res/layout/status_bar_wifi_group.xml
在system_icons.xml文件中,BatteryMeterView 主要是处理电量UI显示,StatusIconContainer 主要是处理wifi和4GUI显示



    

    

在CollapsedStatusBarFragment.java文件中onViewCreated方法中statusIcons就是添加添加状态栏wifi图标和4G图标

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mStatusBar = (PhoneStatusBarView) view;
    if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_PANEL_STATE)) {
        mStatusBar.restoreHierarchyState(
                savedInstanceState.getSparseParcelableArray(EXTRA_PANEL_STATE));
    }
  //start  这里就是添加状态栏wifi图标和4G图标
    mDarkIconManager = new DarkIconManager(view.findViewById(R.id.statusIcons));
    mDarkIconManager.setShouldLog(true);
    Dependency.get(StatusBarIconController.class).addIconGroup(mDarkIconManager);
   //end
     mSystemIconArea = mStatusBar.findViewById(R.id.system_icon_area);
    mClockView = mStatusBar.findViewById(R.id.clock);
    showSystemIconArea(false);
    showClock(false);
    initEmergencyCryptkeeperText();
    initOperatorName();
}

在CollapsedStatusBarFragment.java文件中onDestroyView()方法中移除wifi图标和4G图标

@Override
public void onDestroyView() {
    super.onDestroyView();
    //start 这里就是移除wifi图标和4G图标
    Dependency.get(StatusBarIconController.class).removeIconGroup(mDarkIconManager);
    //end
    if (mNetworkController.hasEmergencyCryptKeeperText()) {
        mNetworkController.removeCallback(mSignalCallback);
    }
}

在StatusBarMobileView .java文件中就是加载4G信号图标和4G信号柱

public static StatusBarMobileView fromContext(Context context, String slot) {
    LayoutInflater inflater = LayoutInflater.from(context);
    StatusBarMobileView v = (StatusBarMobileView)
            inflater.inflate(R.layout.status_bar_mobile_signal_group, null);

    v.setSlot(slot);
    v.init();
    v.setVisibleState(STATE_ICON);
    return v;
}

在status_bar_mobile_signal_group.xml文件中,mobile_signal:4G信号柱 mobile_type:显示4GUI



    
        
        
        
            
        
            
            
        
        
            
        
        
        
            
            
        
    

在StatusBarWifiView .java文件中就是加载wifi图标

public static StatusBarWifiView fromContext(Context context, String slot) {
    Log.d(TAG, "fromContext()");
    LayoutInflater inflater = LayoutInflater.from(context);
    StatusBarWifiView v = (StatusBarWifiView) inflater.inflate(R.layout.status_bar_wifi_group, null);
    v.setSlot(slot);
    v.init();
    v.setVisibleState(STATE_ICON);
    return v;
}

在status_bar_wifi_group.xml文件中wifi_signal表示wifi图标显示,wifi_in和wifi_out表示上行和下行



    
        
            
            
        
        //wifi图标显示
        
            
        

        

        
        

        
    

你可能感兴趣的:(SystemUI,Android系统开发,android,java)