(English) Kotlin Data Classes

Není k dispozici v češtině. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

The main purpose of many classes is to hold data. But to effectively manipulative with data, we need to override quite a lot data. Class holding 3 String values would typically look something like this in Java:
Continue reading

(English) How to check object equality in Kotlin?

Není k dispozici v češtině. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

Unlike Java, Kotlin is purely object-oriented language. There are no primitives, everything is an object. With this said, you might be surprised by results.

Let’s compare two objects with equality operator:

object1 == object2

You expected to get false, right? But answer is true. Why? This code is translated to

a?.equals(b) ?: (b === null)

Continue reading

(English) How to check object equality in Java?

Není k dispozici v češtině. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

Java is not purely object-oriented programming language. We can use both objects and primitives for our variables. We can check easily if two primitives are same by identity operator ==. It is not as easy for objects.

==

Comparing objects with == is one of the frequented beginner’s mistakes. A beginner will check if two Strings with value “apple” are same and the answer is false. Because it doesn’t really check if objects are same but whether they point to the same memory address. How can you then check real equality of objects? Equals is the method you have to use.
Continue reading

(English) Android Studio Live Templates

Není k dispozici v češtině. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

One of best programming practices is DRY. Don’t repeat yourself. And yet we often write similar blocks of code over and over again. And sometimes it really cannot be avoided. You can save yourself lot of time when you meet Android live and file templates. In this post, I write about live templates but I am sure I will come back to file templates later.
So how can you use live templates? Simply type template abbreviation, press Tab and block of code defined in template comes up. There are many live templates already included in Android Studio, but you can also define your own. To see them go to Editor, Settings and Live Templates. There they are, by default sorted by a programming language of their use. Looking like this.
Continue reading

(English) Kotlin Constructors

Není k dispozici v češtině. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

Kotlin helps you make your code shorter and more readable in many areas. One of them is constructors. In Java you have to tediously assign all variables passed to the constructor in similar style

this.something = something 

If more constructors are required, you have to overload them and repeat yourself over and over. Like in the following example.
Continue reading

(English) Static Methods and variables in Kotlin

Není k dispozici v češtině. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

I presume most Java programmers write some helper static methods and most probably even have some helper class including just these. So sooner or later you will need to write static methods like this in Kotlin.

public static float getPxFromDp(Context context, float dp) {
        Resources r = context.getResources();
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
    }

But you will find out you there is not anything like a static method in Kotlin. Fortunately, there are ways around this.
Continue reading

(English) Kotlin Edu

Není k dispozici v češtině. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

There is a lot of ways how to learn Kotlin. Language reference, tutorials, video tutorials, online courses and much more. And now also Kotlin Edu.

Kotlin Educational Tools is Android Studio Plugin that helps you learn Kotlin by giving you small tasks. Read task description, write code and check. And if you cannot find the solution, you can click on Fill answer placeholders to get a right answer. Task description usually includes a link to Kotlin reference page, so you get right at the page with all you need to study to finish a task. It first looks like this.
Continue reading

(English) First Post

Není k dispozici v češtině. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

This is the first post on this blog. I will write mostly about Android programming. About things, I encounter that I find tricky or interesting. I might write about things I am currently studying and trying to make sense of. Because, after first few posts I have prepared, I can say writing about a problem is the best way how to understand it. There will be posts about Kotlin, Android Studio tips and tricks, Google tools, good (bad) old Java and other. Let’s start.

Suntime

Potřebujete vědět, kdy se probudit, abyste viděli východ slunce nebo nevíte, zda se stihnete projít za denního světla během zimního dne? Není třeba dále hledat!
Suntime je aplikace tak jednoduchá jak jen to jde. Vyberte svou polohu a aplikace zobrazí východy a západy slunce v příštích 14 dnech. Po přidání widgetu na domovskou obrazovku to uvidíte kdykoli odemknete telefon.


Get it on Google Play

Čtenářský deník 2.7

Nová verze přidává možnost barevně označit knihy a označit nudnou knihu, kterou už nechcete číst, jako opuštěnou. Bylo opraveno mnoho chyb a skener čárových kódů je výkonnější.

Get it on Google Play