Ardent Android fans know that Easter eggs are hiding in the system. The seventh version called Nougat was no exception. In it, you can activate the game to collect cats. You need to occasionally put a treat in an empty bowl and catch the cat that has come.
The very process of activation Easter eggs described in detail in the blog, here I will tell you what is under the hood.
In the game, cats appear with three-digit numbers. Theoretically, there can be 1,000 cats from 000 to 999 (in fact, no, the program uses a different algorithm, but for us it doesn't matter).
I wondered how they are stored in the application. An Internet search led me to a resource where the
Easter Egg Easter egg sources are posted.
')
Later on Github, I found a
modified code that allows you to run the game as a normal application on any device, not just on Android 7. You can find Google Play using the
Neko Collector keywords.
The second example is more convenient to study, since there is no extra code to activate the Easter egg, which we do not need.
It was not difficult to guess that the main magic happens in the Cat class.
Mustaches, paws, tail - these are my documents.
It turned out that the cats are not stored in the application as separate pictures. Quite understandable, a large number of images will inflate the program. Separate parts of a cat are stored in the
drawable folder as vector resources. For example, this is how the tail is stored in the
tail.xml file.
Paws, eyes, torso, collar, bow, etc. are stored in the same way. And then all this is collected in the constructor of the internal class
CatParts.CatParts(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { body = context.getDrawable(R.drawable.body); head = context.getDrawable(R.drawable.head); leg1 = context.getDrawable(R.drawable.leg1); leg2 = context.getDrawable(R.drawable.leg2); leg3 = context.getDrawable(R.drawable.leg3); leg4 = context.getDrawable(R.drawable.leg4); tail = context.getDrawable(R.drawable.tail); leftEar = context.getDrawable(R.drawable.left_ear); rightEar = context.getDrawable(R.drawable.right_ear); rightEarInside = context.getDrawable(R.drawable.right_ear_inside); leftEarInside = context.getDrawable(R.drawable.left_ear_inside); faceSpot = context.getDrawable(R.drawable.face_spot); cap = context.getDrawable(R.drawable.cap); mouth = context.getDrawable(R.drawable.mouth); foot4 = context.getDrawable(R.drawable.foot4); foot3 = context.getDrawable(R.drawable.foot3); foot1 = context.getDrawable(R.drawable.foot1); foot2 = context.getDrawable(R.drawable.foot2); leg2Shadow = context.getDrawable(R.drawable.leg2_shadow); tailShadow = context.getDrawable(R.drawable.tail_shadow); tailCap = context.getDrawable(R.drawable.tail_cap); belly = context.getDrawable(R.drawable.belly); back = context.getDrawable(R.drawable.back); rightEye = context.getDrawable(R.drawable.right_eye); leftEye = context.getDrawable(R.drawable.left_eye); nose = context.getDrawable(R.drawable.nose); collar = context.getDrawable(R.drawable.collar); bowtie = context.getDrawable(R.drawable.bowtie); } else {
Since the vector has a great opportunity to change the fill on the fly, we randomly select colors and generate a unique cat. The main thing - do not overdo it. You should not paint one paw in black, and the second paw in brown.
If you run the program in the usual mode, the collection of cats will stretch for long hours. Therefore, we substitute the code that is responsible for the interval, setting it to 1 second. Quickly fill the screen.
Definitely worth a dig in the application code and explore other methods. For example, when you want to share a cat caught in social networks, a separate PNG image with a size of 512x512 of good resolution is generated on devices not below Android 6.0 Marshmallow. On older devices, the image is formed through a different method, and the pictures are blurry.
For comparison, the first picture I received on the Android 7 emulator.
And this is a picture taken on an Android 4.4.2 device.
Those who study programming for Android will find it useful to start services using the registration of the JobSheduler scheduler, creating dialogs, using SharedPreferences.
In my opinion, Easter eggs turned out beautiful and cheered me up.
Collect the seals!