首页 > 编程知识 正文

锁屏时间样式,锁屏怎么设置

时间:2023-05-06 15:17:47 阅读:30353 作者:4371

请求:更改SystemUI锁定屏幕接口的时间格式。 Android P的Sysyemui锁定画面界面的日期显示在DateView中不进行处理。 由KeyguardSliceProvider处理并继承内容提供程序

以前安卓o的修改日期是

systemui/src/com/Android/systemui/status bar/policy/dateview.Java

publicdateview (上下文,属性attrs ) (super ) context,attrs ); TypedArray a=context.getTheme ().obtainstyledattributes(attrs,R.styleable.DateView,0,0 ) ); try { mdate pattern=a.getstring (r.style able.dateview _ date pattern ); } finally { a.recycle (); }if(mdatepattern==null ) { mDatePattern=getContext ).getstring (r.string.system _ I _ date _ pattern ); } string date _ format=Android.provider.settings.system.getstring (get context ).getContentResolver )、androing if textutils.isempty(date_format ) { mDatePattern=date_format; } } Android P的更改来自systemui/src/com/Android/systemui/key guard/keyguardsliceprovider.Java

publicbooleanoncreatesliceprovider () { mAlarmManager=getContext ).getsystemservice () alarmmanager.class ); mContentResolver=getContext ().getContentResolver ); mnextalarmcontroller=newnextalarmcontrollerimpl (获取上下文); mnextalarmcontroller.add callback (this; mzenmodecontroller=newzenmodecontrollerimpl (get context )、mHandler ); mzenmodecontroller.add callback (this; mDatePattern=getContext ().getstring ) r.string.system _ ui _ aod _ date _ pattern ); string date _ format=Android.provider.settings.system.getstring (获取上下文).getContentResolver ),Android if textutils.isempty(date_format ) { mDatePattern=date_format; } registerClockUpdate (; 更新时钟(; 返回真; 分析Anndroid P下的处理方式

接受时间的变化,或在此之上的早期,更新时钟方法/* * * * receiverresponsiblefortimetickingandupdatingthedateformat.*/@ visiblefortestingfinalbroadcastreceivermintentreceiver=newbroadcastreceiver ({ @ overridepublicvoidonreceive (上下文) ) if (intent.action _ time _ tick.equals (action ) ) intent.action _ date _ changed.equals ) intent.action _ locale _ changed.equals ) action ) ) if intent.action _ time zone _ changed.equals (action )/nened } mhandler.post (keyguardsliceprovider.this :3360更新时钟); }; }; 获取最新的时间显示,并通知contentprovide显示更新。 mLastText的值与Slice相关,实际上是新的。 protectedvoidupdateclock ((finalstringtext=getformatteddate ); if (! text.equals(mlasttext ) { mLastText=text; mcontentresolver.notify change (msliceuri,null /* observer */); } protectedstringgetformatteddate () if ) mdateformat==null ) { final locale l=locale.get default ); 日期格式格式; string country=get context (.get resources ).getConfiguration ).locale.getCountry ); if(country.equals(xa ) ) format=date format.getinstanceforskeleton ) eemmd ),l ); } else { format=date format.getinstanceforskeleton (mdate pattern,l ); } format.set context (display context.capital ization _ for _ standalone ); Mdate格式=格式; } mcurrenttime.settime (system.current time millis ); 返回日期格式.格式(mcurrenttime; } @ overridepublicsliceonbindslice (urisliceuri ) ) listbuilderbuilder=new list builder (get context ),mSliceUri ); builder.addrow (newrow builder (builder,mDateUri ).settitle ) mlasttext ); 添加下一个(builder; addzenmode(builder; 添加优先级操作(builder; return builder.build (; } protectedvoidaddprimaryaction (listbuilderbuilder )//addsimpleactionbecauseapirequiresit; keyguardhandlespresenting//itsownslicessothisactioniconareactuallyneverused.pendingintentpi=pending intent.get activity sliceactionaction=newsliceaction (pi,icon,mLastText ); rowbuilderprimaryactionrow=newrow builder (builder,uri.parse ) keyguard_action_uri ) (.setprimaryaction )活动}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。