Launcher3 calendar icon changes by date

Source: Internet
Author: User

The launcher icons for dynamic clocks and dynamic calendars were implemented in the previous article, but today's test shows that dynamic calendars have leakreceived problems and cannot cancel received bindings. So today a different way to implement the dynamic calendar icon:

Increase in Launcherappstate.java:

public static final String Action_update_icon = "Com.xxx.update_icon";

Private Launcherappstate () {    ...            ... UPDATE APPICON BEGIN        intentfilter timefilter = new Intentfilter ();        Timefilter.addaction (intent.action_date_changed);        Timefilter.addaction (intent.action_timezone_changed);        Timefilter.addaction ("Android.intent.action.TIME_SET");        Timefilter.addaction (Action_update_icon);        Scontext.registerreceiver (Mmodel, timefilter);        UPDATE APPICON END}

Increase in Launchermodel.java:

Public interface Callbacks {        ...        ... public void Updateappicon (AppInfo info);   UPDATE APPICON}

 @Override public void OnReceive (context context, Intent Intent) {..../**************update APPICON BEGIN            /Else if (Intent.ACTION_DATE_CHANGED.equals (ACTION) | |            Intent.ACTION_TIMEZONE_CHANGED.equals (ACTION) | |            "Android.intent.action.TIME_SET". Equals (action) | |        LauncherAppState.ACTION_UPDATE_ICON.equals (ACTION)) {String pkgname = null;        if (LauncherAppState.ACTION_UPDATE_ICON.equals (ACTION)) {pkgname = Intent.getstringextra ("PackageName");        } else {pkgname = "Com.android.calendar";        } final arraylist<appinfo> list = (arraylist<appinfo>) mBgAllAppsList.data.clone ();        if (null = = List | | list.isempty ()) {return;        } AppInfo info = null;                for (AppInfo ai:list) {if (Ai.componentName.getPackageName (). Equals (Pkgname)) {info = AI;      Break      }} if (null! = info && mcallbacks! = null) {Callbacks callbacks = Mcallbacks.get (            );            if (callbacks! = NULL && info! = null) {Callbacks.updateappicon (info); }}}/**************update APPICON END *****************************/}

Added in Launcher.java:

    UPDATE APPICON BEGIN    @Override public    void Updateappicon (AppInfo info) {        if (null! = Miconcache) {//        Miconcache.updatetitleandicon (info);        Mworkspace.updateshortcut (Info.componentName.getPackageName ());        }    }    UPDATE APPICON END

Added in Workspace.java:

 UPDATE APPICON BEGIN void Updateshortcut (String pkgname) {arraylist<shortcutandwidgetcontainer> child        Renlayouts = Getallshortcutandwidgetcontainers ();            for (Shortcutandwidgetcontainer layout:childrenlayouts) {int childCount = Layout.getchildcount ();                for (int j = 0; J < ChildCount; J + +) {Final view view = Layout.getchildat (j);                Object tag = View.gettag ();                    if (tag instanceof shortcutinfo) {shortcutinfo info = (shortcutinfo) tag;                            try {if (Pkgname.equals (Info.intent.getComponent (). Getpackagename ())) {                            Bubbletextview BV = (Bubbletextview) view;//Bv.applyfromshortcutinfo (info, miconcache);                        Bv.applycalendarinfo (info);                        Bv.invalidate ();         }} catch (Exception e) {}       }}}}//UPDATE APPICON END 
Added in Bubbletextview.java:

    /************************update APPICON start*****************************/public    void Applycalendarinfo ( Shortcutinfo info) {        Bitmap b = Utilities.createcalendariconbitmap (mlauncher);        Fastbitmapdrawable icondrawable = mlauncher.createicondrawable (b);        Icondrawable.setghostmodeenabled (info.isdisabled! = 0);        SetIcon (icondrawable, miconsize);        if (info.contentdescription! = null) {            setcontentdescription (info.contentdescription);        }        SetText (info.title);        Settag (info);//        if (promisestatechanged | | info.ispromise ()) {//            applystate (promisestatechanged);//        }    }       /************************update APPICON end*****************************/

Added in Utilities.java:

UPDATE appiconstatic Bitmap Createcalendariconbitmap (context context) {//time time = new Time ();//time.settonow (); int dayofmonth = Calendar.getinstance (). get (calendar.day_of_month); int dayOfWeek = Calendar.getinstance ()  . get (Calendar.day_of_week);//Canvas.drawbitmap (Getres (mtime.monthday), NULL, getbounds (), mpaint); Bitmap Calendarbackground = Bitmapfactory.decoderesource (Context.getresources (), R.drawable.calendar); Bitmap Dayofmonthres = getcalendardatares (context, dayofmonth); Bitmap Dayofweekres = getcalendarweekdayres (context, dayOfWeek); int width = geticonbitmapsize (); int height = Getico Nbitmapsize (); Bitmap newbmp = bitmap.createbitmap (width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new canvas (newbmp); Rect destrect = new Rect (0, 0, width, height); Rect srcrect = new Rect (0, 0, calendarbackground.getwidth (), Calendarbackground.getheight ()); Canvas.setdrawfilter (new Paintflagsdrawfilter (0, Paint.anti_alias_flag| Paint.filter_bitmap_flag)); Canvas.drawbitmap (Calendarbackground, srcrect, destrect, null), Canvas.drawbitmap (Dayofmonthres, (Width- Dayofmonthres.getwidth ())/2, (Height-dayofmonthres.getheight ())/2 +, NULL); Canvas.drawbitmap (Dayofweekres, (Widt H-dayofweekres.getwidth ())/2, dayofweekres.getheight (), null); Canvas.save (Canvas.all_save_flag); Canvas.restore () ; return newbmp;}

</pre><pre>
Added in Iconcache.java:

Private CacheEntry cachelocked (componentname componentname, Launcheractivityinfocompat info,            Userhandlecompat User, Boolean Usepackageicon, Boolean Uselowresicon) {          ...        .. UPDATE APPICON BEGIN        if (null! = Entry && componentname.getpackagename (). Equals ("Com.android.calendar") {             Entry.icon = Utilities.createcalendariconbitmap (Mcontext);        }        UPDATE APPICON END        return entry;}


It seems to be a bit of a hassle, but there is no error to unregister the broadcast receiver.




Launcher3 calendar icon changes by date

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.