Android9.0 SystemUI 网络信号栏定制修改的流程解析
前情提要
Android8.1平台SystemUI导航栏加载流程解析
9.0改动点简要说明
1、新增StatusBarMobileView替代SignalClusterView,用以控制信号栏显示
同时增加的还有StatusBarIconView、StatusBarWifiView
2、整体流程和8.1类似
效果图
整体流程图
上代码
先来看初始赋值的地方MobileSignalController.java,在notifyListeners()方法中进行我们对应的定制,
最后通过callback.setMobileDataIndicators()将状态值传递到StatusBarSignalPolicy.java解析显示
vendor\mediatek\proprietary\packages\apps\SystemUI\src\com\android\systemui\statusbar\policy\MobileSignalController.java
@Override publicvoidnotifyListeners(SignalCallbackcallback){ MobileIconGroupicons=getIcons(); StringcontentDescription=getStringIfExists(getContentDescription()); StringdataContentDescription=getStringIfExists(icons.mDataContentDescription); if(mCurrentState.inetCondition==0){ dataContentDescription=mContext.getString(R.string.data_connection_no_internet); } finalbooleandataDisabled=mCurrentState.iconGroup==TelephonyIcons.DATA_DISABLED &&mCurrentState.userSetup; ///M:Customizethesignalstrengthiconid.@{ inticonId=getCurrentIconId(); iconId=mStatusBarExt.getCustomizeSignalStrengthIcon( mSubscriptionInfo.getSubscriptionId(), iconId, mSignalStrength, mDataNetType, mServiceState); ///@} if(mSignalStrength!=null){ /*intdbm=mSignalStrength.getDbm(); intasu=mSignalStrength.getAsuLevel(); Log.i("ccz","dbm="+dbm+"asu="+asu);*/ Log.e("ccz","isGSM=="+mSignalStrength.isGsm() +"connected=="+mCurrentState.connected+"dataConnected=="+mCurrentState.dataConnected); } if(mCurrentState.connected){ //cczhengaddgetsignalicon[S] //通过getSignalStrengthIcon方法,根据自定义规则,返回要显示对应资源id iconId=TelephonyIcons.getSignalStrengthIcon(mSignalStrength!=null?mSignalStrength.getDbm():-120, mSignalStrength!=null?mSignalStrength.getAsuLevel():0); //iconId=TelephonyIcons.getSignalStrengthIcon(mCurrentState.level); //cczhengaddgetsignalicon[E] }else{//未连接成功时显示X iconId=R.drawable.stat_sys_signal_disable; } //ShowiconinQSwhenweareconnectedordataisdisabled. booleanshowDataIcon=mCurrentState.dataConnected||dataDisabled; Log.i("ccz","dataDisabled="+dataDisabled+"showDataIcon="+showDataIcon); IconStatestatusIcon=newIconState(mCurrentState.enabled&&!mCurrentState.airplaneMode, iconId,contentDescription); intqsTypeIcon=0; IconStateqsIcon=null; Stringdescription=null; //OnlysenddatasimcallbackstoQS. if(mCurrentState.dataSim){ qsTypeIcon=(showDataIcon||mConfig.alwaysShowDataRatIcon)?icons.mQsDataType:0; qsIcon=newIconState(mCurrentState.enabled &&!mCurrentState.isEmergency,getQsCurrentIconId(),contentDescription); description=mCurrentState.isEmergency?null:mCurrentState.networkName; } booleanactivityIn=mCurrentState.dataConnected &&!mCurrentState.carrierNetworkChangeMode &&mCurrentState.activityIn; booleanactivityOut=mCurrentState.dataConnected &&!mCurrentState.carrierNetworkChangeMode &&mCurrentState.activityOut; showDataIcon&=mCurrentState.isDefault||dataDisabled; inttypeIcon=(showDataIcon||mConfig.alwaysShowDataRatIcon)?icons.mDataType:0; ///M:Addforlwa. typeIcon=mCurrentState.lwaRegState==NetworkTypeUtils.LWA_STATE_CONNCTED &&showDataIcon?NetworkTypeUtils.LWA_ICON:typeIcon; /**M:Support[NetworkTypeonStatusBar],changetheimplementmethods. *Getthenetworkiconbaseonservicestate. *Addonemoreparameterfornetworktype. *@{**/ intnetworkIcon=mCurrentState.networkIcon; ///M:Supportvolteicon.Bugfixwhenairplanemodeisongotohidevolteicon intvolteIcon=mCurrentState.airplaneMode&&!isImsOverWfc() ?0:mCurrentState.volteIcon; ///M:whendatadisabled,commonshowdataiconasx,butopdonotneedshowit@{ mStatusBarExt.isDataDisabled(mSubscriptionInfo.getSubscriptionId(),dataDisabled); ///@} ///M:Customizethedatatypeiconid.@{ typeIcon=mStatusBarExt.getDataTypeIcon( mSubscriptionInfo.getSubscriptionId(), typeIcon, mDataNetType, mCurrentState.dataConnected?TelephonyManager.DATA_CONNECTED: TelephonyManager.DATA_DISCONNECTED, mServiceState); ///@} ///M:Customizethenetworktypeiconid.@{ networkIcon=mStatusBarExt.getNetworkTypeIcon( mSubscriptionInfo.getSubscriptionId(), networkIcon, mDataNetType, mServiceState); ///foroperator //通过description传递运营商信息 description=mCurrentState.operator; //forqsdatetype qsTypeIcon=mCurrentState.mQsDataType; ///@} //cczhengaddforwhendatadisablesetmMobileDataActivityGONE[S] //数据网络关闭时,id置为0,不显示上下行小箭头 if(isDataDisabled()){ typeIcon=0; } Log.d("ccz","qsTypeIcon="+qsTypeIcon); //cczhengaddforwhendatadisablesetmMobileDataActivityGONE[E] Log.e("ccz","showDataIcon="+showDataIcon+"activityIn="+activityIn +"activityOut="+activityOut); Log.i("ccz","networkName="+mCurrentState.networkName+"description="+description); callback.setMobileDataIndicators(statusIcon,qsIcon,typeIcon,networkIcon,volteIcon, qsTypeIcon,activityIn,activityOut,dataContentDescription,description, icons.mIsWide,mSubscriptionInfo.getSubscriptionId(),mCurrentState.roaming, mCurrentState.isDefaultData,mCurrentState.customizedState); ///M:updateplmnlabel@{ mNetworkController.refreshPlmnCarrierLabel(); ///@} } privatefinalvoidupdateTelephony(){ ..... ///M:Fornetworktypebigicon. mCurrentState.networkIcon= NetworkTypeUtils.getNetworkTypeIcon(mServiceState,mConfig,hasService()); ///M:Forvoltetypeicon. mCurrentState.volteIcon=getVolteIcon(); //cczhengaddforqsdatetype mCurrentState.mQsDataType=((MobileIconGroup)mCurrentState.iconGroup).mQsDataType; //cczhengaddforoperator mCurrentState.operator=getOperatorType(); notifyListenersIfNecessary(); } privateStringgetOperatorType(){ if(!hasService()){ //Notinservice,don'tshowoperator return"0"; } intoperatorType=NetworkTypeUtils.getOperatorType(mPhone); if(operatorType==0) return"0"; else returnmContext.getResources().getString(operatorType); }
根据通用标准自定义显示规则
dbm>=-1074格
-107>dbm>=-1113格
-111>dbm>=-1142格
-114>dbm>=-1171格
vendor\mediatek\proprietary\packages\apps\SystemUI\src\com\android\systemui\statusbar\policy\TelephonyIcons.java
staticfinalint[]TELEPHONY_SIGNAL_STRENGTH_FULL={ R.drawable.stat_sys_signal_0_fully, R.drawable.stat_sys_signal_1_fully, R.drawable.stat_sys_signal_2_fully, R.drawable.stat_sys_signal_3_fully, R.drawable.stat_sys_signal_4_fully, }; /** *CustomizeSignalstrengthicon. *@paramleveltelephonysignalstrengthleve. *@returnSignalstrengthiconid. */ staticfinalintgetSignalStrengthIcon(intlevel){ android.util.Log.e("ccz","getSignalStrengthIcon()level=="+level); if(level>=0&&level=-107)level=4; elseif(dbm>=-111)level=3; elseif(dbm>=-114)level=2; elseif(dbm>=-117)level=1; android.util.Log.e("ccz","getSignalStrengthIcon()dbm=="+dbm+"asu=="+asu+"level=="+level); returnTELEPHONY_SIGNAL_STRENGTH_FULL[level]; }
舍弃原来的网络大图标,新增网络小图标,这样可以在下方显示网络数据图标
vendor\mediatek\proprietary\packages\apps\SystemUI\src\com\mediatek\systemui\statusbar\networktype\NetworkTypeUtils.java
//cczhengaddshowsmallnetworkType staticfinalMapsNetworkTypeSmallIcons=newHashMap (){ { //ForCDMA3G put(TelephonyManager.NETWORK_TYPE_EVDO_0,R.drawable.stat_sys_data_fully_connected_3g); put(TelephonyManager.NETWORK_TYPE_EVDO_A,R.drawable.stat_sys_data_fully_connected_3g); put(TelephonyManager.NETWORK_TYPE_EVDO_B,R.drawable.stat_sys_data_fully_connected_3g); put(TelephonyManager.NETWORK_TYPE_EHRPD,R.drawable.stat_sys_data_fully_connected_3g); //ForCDMA1x put(TelephonyManager.NETWORK_TYPE_CDMA,R.drawable.stat_sys_data_fully_connected_1x); put(TelephonyManager.NETWORK_TYPE_1xRTT,R.drawable.stat_sys_data_fully_connected_1x); //Edge put(TelephonyManager.NETWORK_TYPE_EDGE,R.drawable.stat_sys_data_fully_connected_e); //3G put(TelephonyManager.NETWORK_TYPE_UMTS,R.drawable.stat_sys_data_fully_connected_3g); //For4G put(TelephonyManager.NETWORK_TYPE_LTE,R.drawable.stat_sys_data_fully_connected_4g); //3G put(TelephonyManager.NETWORK_TYPE_HSDPA,R.drawable.stat_sys_data_fully_connected_3g); put(TelephonyManager.NETWORK_TYPE_HSUPA,R.drawable.stat_sys_data_fully_connected_3g); put(TelephonyManager.NETWORK_TYPE_HSPA,R.drawable.stat_sys_data_fully_connected_3g); put(TelephonyManager.NETWORK_TYPE_HSPAP,R.drawable.stat_sys_data_fully_connected_3g); put(TelephonyManager.NETWORK_TYPE_IWLAN,0); } }; publicstaticintgetNetworkTypeIcon(ServiceStateserviceState,Configconfig, booleanhasService){ if(!hasService){ //Notinservice,nonetworktype. return0; } inttempNetworkType=getNetworkType(serviceState); //cczhengchangesNetworkTypeIconstosNetworkTypeSmallIcons,showsmallnetworkType //IntegericonId=sNetworkTypeIcons.get(tempNetworkType); IntegericonId=sNetworkTypeSmallIcons.get(tempNetworkType);//add if(iconId==null){ iconId=tempNetworkType==TelephonyManager.NETWORK_TYPE_UNKNOWN?0: config.showAtLeast3G?R.drawable.stat_sys_network_type_3g: R.drawable.stat_sys_network_type_g; } Log.i("ccz","Operator=="+serviceState.getOperatorAlphaLong()); returniconId.intValue(); } //cczhengaddforoperatortype staticfinalint[]OPERATOR_TYPE={ R.string.operator_cmcc,//CHINA_MOBILE R.string.operator_cucc,//CHINA_UNICOM R.string.operator_ctcc//CHINA_TELECOM }; publicstaticintgetOperatorType(TelephonyManagertelephonyManager){ inttype=0; Stringoperator=telephonyManager.getSimOperator(); switch(operator){ case"46000": case"46002": case"46007": case"41004": type=OPERATOR_TYPE[0]; break; case"46001": case"46006": type=OPERATOR_TYPE[1]; break; case"46003": case"46011": type=OPERATOR_TYPE[2]; break; default: break; } returntype; }
StatusBarSignalPolicy通过description传递运营商类型
vendor\mediatek\proprietary\packages\apps\SystemUI\src\com\android\systemui\statusbar\phone\StatusBarSignalPolicy.java @Override publicvoidsetMobileDataIndicators(IconStatestatusIcon,IconStateqsIcon,intstatusType, intnetworkType,intvolteIcon,intqsType,booleanactivityIn,booleanactivityOut, StringtypeContentDescription,Stringdescription,booleanisWide,intsubId, booleanroaming,booleanisDefaultData,intcustomizedState){ Log.i("ccz","StatusBarSignalPolicysetMobileDataIndicators()"); MobileIconStatestate=getState(subId); if(state==null){ return; } ..... //cczhengaddforoperatorbecausedescriptionisunless state.mOperator=description; Log.e("ccz","mMobileStrengthId="+statusIcon.icon); //Alwayssendacopytomaintainvaluetypesemantics mIconController.setMobileIcons(mSlotMobile,MobileIconState.copyStates(mMobileStates)); }
StatusBarMobileView获取传递的资源id值显示对应的图标
vendor\mediatek\proprietary\packages\apps\SystemUI\src\com\android\systemui\statusbar\StatusBarMobileView.java publicclassStatusBarMobileViewextendsFrameLayoutimplementsDarkReceiver, StatusIconDisplayable{ privatestaticfinalStringTAG="StatusBarMobileView"; .... //cczhengadd privateImageViewmMobileDataActivity; privateTextViewmOperatorType; privatevoidinit(){ .... mNetworkType=findViewById(R.id.network_type); mVolteType=findViewById(R.id.volte_indicator_ext); ///@} mMobileDataActivity=findViewById(R.id.data_inout); mOperatorType=findViewById(R.id.tv_operator); mMobileDrawable=newSignalDrawable(getContext()); //cczhengannotaiondon'tusesystemfullstyle //mMobile.setImageDrawable(mMobileDrawable); initDotView(); mIsWfcEnable=SystemProperties.get("persist.vendor.mtk_wfc_support").equals("1"); ///M:AddforPluginfeature@{ mStatusBarExt=OpSystemUICustomizationFactoryBase.getOpFactory(mContext) .makeSystemUIStatusBar(mContext); ///@} } privatevoidinitViewState(){ setContentDescription(mState.contentDescription); if(!mState.visible){ mMobileGroup.setVisibility(View.GONE); }else{ mMobileGroup.setVisibility(View.VISIBLE); } //cczhengdon'tusesystemstylechangeemptylinestyle注释原来的实心信号格 //mMobileDrawable.setLevel(mState.strengthId); mMobile.setImageResource(mState.strengthId); //showdateinouticon数据流量小箭头 mMobileDataActivity.setImageResource(getDataActivityIcon(mState.activityIn,mState.activityOut)); if(mState.typeId>0){ if(!mStatusBarExt.disableHostFunction()){ mMobileType.setContentDescription(mState.typeContentDescription); mMobileType.setImageResource(mState.typeId); } //cczhenghidesmalldatatypeiconxor4G mMobileType.setVisibility(View.GONE/*View.VISIBLE*/); }else{ mMobileType.setVisibility(View.GONE); } mMobileRoaming.setVisibility(mState.roaming?View.VISIBLE:View.GONE); mIn.setVisibility(mState.activityIn?View.VISIBLE:View.GONE); mOut.setVisibility(mState.activityIn?View.VISIBLE:View.GONE); //mInoutContainer.setVisibility((mState.activityIn||mState.activityOut) //?View.VISIBLE:View.GONE); mMobileDataActivity.setVisibility(mState.typeId!=0?View.VISIBLE:View.GONE); ///M:Addfor[NetworkTypeandvolteonStatusbar]@{ setCustomizeViewProperty(); ///@} showWfcIfAirplaneMode(); ///M:Adddatagroupforpluginfeature.@{ mStatusBarExt.addCustomizedView(mState.subId,mContext,mMobileGroup); setCustomizedOpViews(); ///@} } privatevoidupdateState(MobileIconStatestate){ setContentDescription(state.contentDescription); if(mState.visible!=state.visible){ mMobileGroup.setVisibility(state.visible?View.VISIBLE:View.GONE); //ToavoidStatusBarMobileViewwillnotshowinextremecase, //forcerequestlayoutonceifvisiblestatechanged. requestLayout(); } if(mState.strengthId!=state.strengthId){ //cczhengdon'tusesystemstylechangeemptylinestyle //mMobileDrawable.setLevel(state.strengthId); mMobile.setImageResource(state.strengthId); } //showdateinouticon mMobileDataActivity.setImageResource(getDataActivityIcon(state.activityIn,state.activityOut)); if(mState.typeId!=state.typeId){ if(state.typeId!=0){ if(!mStatusBarExt.disableHostFunction()){ mMobileType.setContentDescription(state.typeContentDescription); mMobileType.setImageResource(state.typeId); } //cczhenghidesmalldatatypeiconxor4G //数据流量标识mMobileDataActivity替代mMobileType mMobileType.setVisibility(View.GONE/*View.VISIBLE*/); }else{ mMobileType.setVisibility(View.GONE); } } mMobileRoaming.setVisibility(state.roaming?View.VISIBLE:View.GONE); mIn.setVisibility(state.activityIn?View.VISIBLE:View.GONE); mOut.setVisibility(state.activityIn?View.VISIBLE:View.GONE); //mInoutContainer.setVisibility((state.activityIn||state.activityOut) //?View.VISIBLE:View.GONE); mMobileDataActivity.setVisibility(state.typeId!=0?View.VISIBLE:View.GONE); ///M:Addfor[NetworkTypeandvolteonStatusbar]@{ if(mState.networkIcon!=state.networkIcon){ setNetworkIcon(state.networkIcon); } if(mState.volteIcon!=state.volteIcon){ setVolteIcon(state.volteIcon); } if(mState.mOperator!=state.mOperator){ setOperatorText(state.mOperator); } if(mState.mCustomizedState!=state.mCustomizedState ||mState.networkIcon!=state.networkIcon){ //ifcsregstatehaschangedornetworkiconchangetoLTE,needtoupdate. mStatusBarExt.setDisVolteView(mState.subId,state.volteIcon,mVolteType); } ///@} mState=state; //shouldaddedaftersetmState showWfcIfAirplaneMode(); setCustomizedOpViews(); } //cczhengaddfordatainouticon[S] finalintDATA_ACTIVITY_NONE=R.drawable.ct_stat_sys_signal_not_inout; finalintDATA_ACTIVITY_IN=R.drawable.ct_stat_sys_signal_in; finalintDATA_ACTIVITY_OUT=R.drawable.ct_stat_sys_signal_out; finalintDATA_ACTIVITY_INOUT=R.drawable.ct_stat_sys_signal_inout; /** *M:getDataActivityIcon:GetDataActivityiconbydataActivitytype. *@paramactivityIn:dataActivityType *@paramactivityOut:dataActivityType *@returndataActivityiconID */ publicintgetDataActivityIcon(booleanactivityIn,booleanactivityOut){ Log.i("ccz","mActivityIn="+activityIn+"mActivityOut="+activityOut); inticon=DATA_ACTIVITY_NONE; if(activityIn&&activityOut){ icon=DATA_ACTIVITY_INOUT; }elseif(activityIn){ icon=DATA_ACTIVITY_IN; }elseif(activityOut){ icon=DATA_ACTIVITY_OUT; } returnicon; } //cczhengaddfordatainouticon[S] privatevoidsetOperatorText(StringmOperator){ if("0".equals(mOperator)){ mOperatorType.setVisibility(View.GONE); }else{ mOperatorType.setText(mOperator); mOperatorType.setVisibility(View.VISIBLE); } }
StatusBarMobileView对应布局文件status_bar_mobile_signal_group修改
vendor\mediatek\proprietary\packages\apps\SystemUI\res\layout\status_bar_mobile_signal_group.xml
.......
总结
以上所述是小编给大家介绍的Android9.0SystemUI网络信号栏定制修改,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。