Android Launcher calendar icon display date

Source: Internet
Author: User

See the number on the iphone calendar icon will change with the date changes, recently on the Android platform also studied, the implementation method is as follows:

directly on the source

Changed it in the launcher.

First, in the Iconcache.java file, find the method private CacheEntry cachelocked (componentname componentname, ResolveInfo info,
Hashmap<object, charsequence> Labelcache)
In Entry.icon = Utilities.createiconbitmap (icon, mcontext); This position is modified:

<span style= "FONT-SIZE:14PX;" >if (Info.activityInfo.packageName.equals ("Com.android.calendar")) {                Entry.icon = Utilities.createcalendariconbitmap (icon, mcontext);            } else{                if (index >= 0) {                    Entry.icon = Utilities.createiconbitmap (icon, mcontext);                } else {                    Entry.icon = Utilities.createiconbitmap (/                            * sprd:feature 253522, Remove the application drawer view @{*                            ///Getfullresicon ( info), mcontext);                        Icon, Mcontext, True);                }            } </span>


The following source code is changed:

<span style= "FONT-SIZE:14PX;" >private cacheentry cachelocked (componentname componentname, ResolveInfo info, hashmap<object, CharSequen        Ce> labelcache) {CacheEntry entry = Mcache.get (componentname);            if (entry = = null) {entry = new cacheentry ();            Mcache.put (componentname, entry);            ComponentName key = Launchermodel.getcomponentnamefromresolveinfo (info); if (Labelcache! = null && Labelcache.containskey (key)) {Entry.title = Labelcache.get (key). toString            ();                } else {entry.title = Info.loadlabel (Mpackagemanager). toString ();                if (Labelcache! = null) {Labelcache.put (key, Entry.title);            }} if (entry.title = = null) {entry.title = Info.activityInfo.name; }/* Sprd:fix bug 281291, remove icon_top for theme Defaut icon @{*/* Sprd:uui Theme:systemIcons @{*/drawable icon; /* Sprd:fix bug294355, add just to Thememanager.            @{*/INT index = Sysindexof (Componentname.getclassname ());            LOG.I ("JXT", "Index:" +index+ ", Name:" +componentname.getclassname () "); icon = Getfullresicon (info);//changed by Leo if (Info.activityInfo.packageName.equals ("Com.android.calendar"))            {Entry.icon = Utilities.createcalendariconbitmap (icon, mcontext);                }else{if (index >= 0) {Entry.icon = Utilities.createiconbitmap (icon, mcontext); } else {Entry.icon = Utilities.createiconbitmap (/* sprd:feat                        Ure 253522, Remove the application drawer view @{*///Getfullresicon (info), mcontext);                Icon, Mcontext, true); }}/* @} */* @} */* @} */} return entry;   }</span> 

Next Modify Utilities.java

Add a function:


<span style= "FONT-SIZE:14PX;" >static Bitmap createcalendariconbitmap (drawable icon, context context) {Bitmap Calendaricon = Createiconbitmap (        Icon,context);                String daystring = string.valueof (Calendar.getinstance (). Get (Calendar.day_of_month));            Synchronized (Scanvas) {final canvas canvas = Scanvas;                        Canvas.setbitmap (Calendaricon);                        Final float mdensity = context.getresources (). Getdisplaymetrics (). density;            Paint Mdatepaint = new paint ();            Mdatepaint.settypeface (Typeface.default_bold);            Mdatepaint.settextsize ((int) 30F * mdensity);            Mdatepaint.setcolor (0xff000000);            Mdatepaint.setantialias (TRUE);            Rect rect = new rect ();            Mdatepaint.gettextbounds (Daystring,0,daystring.length (), rect);            int hoffset = 20;            int width1 = Rect.right-rect.left;            int height1 = Rect.bottom-rect.top; int width2 =Calendaricon.getwidth ();                        int height2 = calendaricon.getheight () + Hoffset;                        Canvas.drawtext (daystring, (width2-width1)/2-rect.left, (height2-height1)/2-rect.top,mdatepaint);            Canvas.setbitmap (NULL);        return Calendaricon; }}</span>
then modify the Launchermodel.java file:

Add the following code in the OnReceive () method:

<span style= "FONT-SIZE:14PX;" >//changed by Leo        }else if (Intent.ACTION_DATE_CHANGED.equals (ACTION) | |                Intent.ACTION_TIME_CHANGED.equals (ACTION) | |                Intent.ACTION_TIMEZONE_CHANGED.equals (ACTION) {            final String PackageName = "Com.android.calendar";            enqueuepackageupdated (New Packageupdatedtask (                    packageupdatedtask.op_update, New String[]{packagename}));        </span>
finally modify the Launcherapplication.java file, if it is Launcher3 source, then modify the Launcherappstate.java file

What I'm modifying here is

Launcherappstate.java

In the constructor private Launcherappstate (), add:

<span style= "FONT-SIZE:14PX;" >//changed by Leo        Filter.addaction (intent.action_time_changed);        Filter.addaction (intent.action_date_changed);        Filter.addaction (intent.action_timezone_changed);</span>

The modified style is:

<span Style= "FONT-SIZE:14PX;"        >/Register Intent receivers Intentfilter filter = new Intentfilter (intent.action_package_added);        Filter.addaction (intent.action_package_removed);        Filter.addaction (intent.action_package_changed);        Filter.adddatascheme ("package");        Scontext.registerreceiver (Mmodel, filter);        Filter = new Intentfilter ();        Filter.addaction (intent.action_external_applications_available);        Filter.addaction (intent.action_external_applications_unavailable);        Filter.addaction (intent.action_locale_changed); Filter.addaction (intent.action_configuration_changed);        Changed by Leo Filter.addaction (intent.action_time_changed);        Filter.addaction (intent.action_date_changed);                Filter.addaction (intent.action_timezone_changed); Scontext.registerreceiver (Mmodel, filter); </span> 
Of course, this is not run to see the effect, to import the package is imported, and then single-compiled launcher module, push to the phone, you can see the calendar icon displays the current 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.