Tag Archiv: php

20 Excellent Resources for Learning Kotlin

20-kotlin-resources

Кotlin is a modern programming language that runs on the Java Virtual Machine. It has an elegant syntax and is interoperable with all existing Java libraries. In the 2017 Google I/O, the Android team announced that Kotlin will become an official programming language for the Android platform. This puts Kotlin in position to become one of the top programming languages of the future.

To help you get started with your Kotlin journey, we’ve curated a list of some of the best Kotlin learning resources available right now. We haven’t included any paid courses or books, everything on the list is 100% free.


The Kotlin Website

The official website for the project is a very good place to start your Kotlin education. In the reference section you can find in-depth documentation that covers all the main concepts and features of the language. The tutorials section has a variety of practical step-by-step guides on setting up a working environment and working with the compiler.

There is also the Kotlin editor, a browser app that let’s you try out the language. It is loaded with many examples including the Koans course – by far the best way to get familiar with the syntax.

Keddit: Learn Kotlin while developing an Android App

An excellent 11-part series by Juan Ignacio Saravia in which he puts Kotlin into action and builds a Reddit clone app. The tutorials cover a vast number of topics ranging from setting up the workspace to using APIs and even unit testing. The code is available on GitHub.

Antonio Leiva’s Blog

Antoni Leiva’s blog is dedicated to all things Kotlin. It is updated weekly(ish) with high-quality tutorials and articles in which more advanced Kotlin developers can learn about new libraries and find all kinds of practical techniques.

Android Announces Support for Kotlin

The official Google blog post that explains the reasons behind the exciting announcement and why Kotlin deserves a place in the Android ecosystem. The article then goes on to give a brief preview of some of the awesome syntax improvements that Kotlin brings.

Design Patterns implemented in Kotlin

Dariusz Baciński has created a useful GitHub repo containing common design patterns implemented in Kotlin. There are similar projects written in several languages including Java, Swift, JavaScript, and PHP, so if you are coming from one of these programming background you can use them as a reference point.

Learn X in Y minutes

A quick cheatsheet with some of the most important features and syntax quirks that will help you write better Kotlin code. There are examples on working with classes, loops, and lists, as well as implementations of classic programming problems such as generating a Fibonacci sequence.

The Kotlin Blog

The official blog for Kotlin by its authors at JetBrains. Here you can find all Kotlin related news and updates, as well as all kinds of tutorials, tips, and other useful articles.

Get Started with Kotlin on Android

A helpful article from the Google Developers blog that explains how to setup Android Studio for Kotlin, how to convert .java files to .kt files, and how to incorporate the new language into an existing Android project. There are also some code comparisons on the same Android APIs used with both Kotlin and Java.

Android Testing With Kotlin

Great article that shows us how to write and run tests for Android apps using Kotlin. The author does a great job of explaining what different types of tests are available, when to use them, and how to make sure we are testing properly. Another good tutorial on this topic can be found here.


Introduction to Kotlin

A talk from Google I/O 2017 dedicated to introducing Kotlin to people for the first time and giving them an idea of how it can improve their workflow. It covers many of the basics and showcases some cool Kotlin tips.

Life is Great and Everything Will Be Ok, Kotlin is Here

The second Kotlin talk from Google I/O 2017. This one covers more advanced topics like design patterns, best practices, and other common principles. It also sheds some light on what it is like to use Kotlin in production and the challenges of adopting a young language in the workplace.

Peter Sommerhoff’s Kotlin Tutorials

Here is a free Kotlin course for complete beginners that includes all the basics from variables to conditionals to loops and functions. It then goes on to more advanced topics like object-orientation in Kotlin and functional programming like lambda expressions.

Better Android Development with Kotlin & Gradle

This talk from 2016 consists of a brief overview of the language’s features followed by a real world example where you’ll learn how Kotlin fits in with the existing tools in a typical Android workflow.

Better Android Development with Kotlin & Gradle

A very good 8-minute tutorial that quickly goes over the most important Kotlin features, such as the shortened variable declarations, lambdas, extension function, and more.

Android Development with Kotlin — Jake Wharton

Introduction to Kotlin that explains how the new language will improve the Android ecosystem and shows us a number of cool ways we can use the smart Kotlin syntax to our advantage.


From Java To Kotlin

Useful cheatsheet containing short snippets of code that will help you quickly look up the Kotlin alternatives to common Java operators, functions, and declarations.

Kotlin Educational Plugin

A plugin for IntelliJ IDEs that allows you to take the Koans course in a local offline environment.

Kotlin on GitHub

Kotlin has been open-source for more than 5 years and there is a GitHub repo containing the entire history of the project. If you want to support the language there are multiple ways you can contribute, be it directly or by working on the docs.

Kotlin Android Template

Template Android project that makes it super easy to setup a stable Kotlin workspace and quickly bootstrap your apps.

Awesome Kotlin

An extensive list of Kotlin resources containing all sorts of useful links, books, libraries, frameworks, and videos. The list is very well organized, with a stylized version also available at kotlin.link.

Getting Started With The JavaScript Web Animation API

js-animations

Adding animations to web interfaces makes pages and apps feel more responsive and interactive. A side menu that smoothly slides out of view provides a much better user experience then a menu that just disappears when you close it.

So far creating web animations was done either via CSS transitions, CSS keyframes, or an external library such as Animate.css or Velocity. Thanks to a new native JavaScript API, we are now able to freely animate any HTML element without ever having to leave our .js file.

Creating Animations

To showcase the awesomeness of the new API, let’s build a super simple example, once the old-fashioned CSS way, then with JavaScript Web Animations.

The editor below contains two HTML divs that when clicked on move to the right and then change their color. The square is animated via CSS @keyframes, and the circle via the Web Animations API.

(Play with our code editor on Tutorialzine.com)

The @keyframes animation should be familiar to most developers so let’s look at that first.

The CSS Approach

Our CSS animation is defined in a @keyframes block that represents a timeline of all the transitions. Once we have our choreography defined, we can map it to a selector via the animation property and it’s options.

.animate {
    animation-name: move-and-change-color;   
    animation-duration: 0.4s;
    animation-fill-mode: forwards;
}

@keyframes move-and-change-color {
    0% {
        transform: translateX(0);
    }

    80% {
        transform: translateX(100px);
        background-color: #2196F3;
    }

    100% {
        transform: translateX(100px);
        background-color: #EF5350;
    }
}

We want the animation to start on user interaction so we will also have to create an on-click event listener that adds a CSS class to the desired element:

var square = document.getElementById('square');
    
square.addEventListener('click', function() {
    square.className += " animate";
});

Although it works pretty well, the CSS approach seems rather non-intuitive as we define what happens in the stylesheets, but actually start it in the JavaScript. We also have very limited control over the animation once it has been invoked. Both these problems can be solved by switching to the Web Animation API.

The JavaScript Approach

We can describe our JavaScript animation using almost the exact same transitions we used in the CSS example:

var moveAndChangeColor = [
    { 
        transform: 'translateX(0)',
        background: '#2196F3'    // blue
    },
    { 
        offset: 0.8,
        transform: 'translateX(100px)', 
        background: '#2196F3'    // blue
    },
    {
        transform: 'translateX(100px)',
        background: '#EF5350'    // red
    }
];

Each object in the array represents a state of the animation. The states are evenly distributed in time (3 states – 0%, 50%, 100%) unless we change the timing using the offset option, as we’ve done with the middle state.

After we’ve defined our animation array, we can invoke it using the animate() method. It takes as a second argument an object with the same options as the CSS animation property, although with slightly different names (e.g. animation-fill-mode is fill, animation-iteration-count is iteration, etc).

var circle = document.getElementById('circle');
  
circle.addEventListener('click', function() {
    circle.animate(moveAndChangeColor, {
        duration: 400,
        fill: 'forwards'
    });
});

As you can see, the JavaScript approach is much more organized with the animation stored in a variable and the animate() method used for invoking it whenever we need to.

Controlling Animations

The Web Animation API also makes it possible to easily control the playback of an animation in a number of ways. The animate() method returns an Animation object which we can save in a variable and use to refer to that animation later on.

var animation = elem.animate(transitions, options);

The interface provides us with the following methods:

  • pause() – Freezes the animation in its current state.
  • play() – Resumes the animation or restarts it if it has finished.
  • reverse() – Plays the transitions backwards.
  • finish() – Goes to the end of the animation (or the beginning if reversed).
  • cancel() – Stops playback and returns to starting state.

Below is a tiny demo with a loading indicator that loops infinitely. We’ve setup buttons for the different events so that you can try them out:

(Play with our code editor on Tutorialzine.com)

Properties and Events Listeners

The Animation object returned from animate() holds several useful properties that give us access to options like the current time, the playback rate, and others. Although some are read-only, most of the properties can be used as setters and getters.

You can view the JS code in the editor below to get a sense of how they work. For the full list of properties visit MDN.

(Play with our code editor on Tutorialzine.com)

In addition to that, the Web Animation API provides us with two useful event handlers for when the animation has finished or has been canceled:

spinnerAnimation.addEventListener('finish', function() {
    // Animation has completed or .finish() has been called.
    doSomething();
});

spinnerAnimation.addEventListener('cancel', function() {
    // Animation has been canceled.    
    doSomething();
});

Support and Performance

Most of the Web Animation features are freely available in Chrome and Firefox, with Edge and Safari implementations in the working (caniuse). There is also a well maintained open-source polyfill which can be used while waiting for full browser coverage.

When it comes to performance, there shouldn’t be any difference compared to regular CSS transitions, as browsers use the same engine for both. If you stick to animating only properties that don’t cause redraws, such as transform and opacity, animations should keep a steady 60fps rate.

Conclusion

The Web Animation API gives developers an awesome new way to create and control web animations using nothing but pure JavaScript. For animations that are invoked on user interaction or other dynamic events, this is great news since the whole animation can be done in the controller code, without having to jump to a CSS file for the actual transitions.

This article covered most of the features of the new API, but if you want to learn more here are a couple of excellent resources we highly recommend:

5 Beautiful Image Effects With CSS Shapes and Filters

5-beautiful-image-effects-with-css

Today we’ve prepared for you five background images showcasing the power of modern CSS. They can be used as desktop wallpapers, eye-catching landing pages, and even as printed posters. In the article below we’ll also go over some of the key CSS techniques, so that you can customize them to your liking or make your own ones from scratch.

The Designs

A Polyscape (poly = many, scape = scenery) is an image that contains multiple pictures mixed into one, creating very pleasing surrealistic visuals. Usually such design are made in Photoshop or other image editing software, but thanks to the ever growing arsenal of CSS properties, awesome polyscapes can now be created using nothing but simple web technologies!

You can view the designs in a demo app we created. The full source code plus all the polyscapes exported into HD images can be downloaded as a .zip archive from the Download button near the top of this page.

The demo uses some experimental CSS properties which might not work in all browsers. For the full experience, it’s best to open it in Chrome.

Polyscape of a mountain with CSS shapes and filters

Polyscape of a mountain with CSS shapes and filters.

Making these polyscapes was very easy and we had a lot of fun in the process. For the backgrounds we used images from Unsplash. Everything else is done via various CSS shapes, transforms, and filters.

CSS Shapes

The designs use a variety of geometrical shapes made out of CSS. Here is how they are done:

  • Squares – HTML blocks are rectangular by default. Just choose height and width. To turn them sideways we use transform: rotate(45deg);.
  • Circles – Circular shapes in CSS can be created by adding border-radius: 50%; to a square shape.
  • Triangles and Diamonds – Possible thanks to clip-path. We’ve recently wrote about this in detail in our article CSS Triangles Without Ugly Hacks. Check it out!

Another interesting CSS shape we wanted to make is a square that is transparent inside but has an image as its border:

Borders can have images as background.

Tilted squares with transparent background and image border.

It turns out there is a CSS spec that does exactly that – it’s called border-image and takes as parameters the path to an image, the border size, and how to place the image.

background: transparent;
border: 25px solid transparent;
border-image: url(clouds.jpg) 25 stretch;

CSS Filters

Since we are adding images on top of an image background, in many cases we need to apply some filters to make the two views stand out. Most modern browsers freely support this feature under the filter property.

It allows us to shift the hue from one color to another, boost the contrast, make everything black-and-white, and others. Here is a list of all the available CSS filters:

  • grayscale
  • hue-rotate
  • invert
  • contrast
  • blur
  • brightness
  • opacity
  • saturate
  • sepia
  • drop-shadow

We can combine as many filters as we like until we get the desired result:

filter: hue-rotate(60deg) contrast(200%) blur(2px);

Conclusion

We hope you’ve enjoyed our little CSS experiment. The demo and all of the code is 100% free, and you have all rights to use, share, and change the designs (our license).

Powered by Gewgley