Kotlin Programming Cookbook
eBook - ePub

Kotlin Programming Cookbook

Aanand Shekhar Roy, Rashi Karanpuria, Mitchell Wong Ho

Partager le livre
  1. 434 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Kotlin Programming Cookbook

Aanand Shekhar Roy, Rashi Karanpuria, Mitchell Wong Ho

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

Discover Android programming and web development by understanding the concepts of Kotlin ProgrammingAbout This Book‱ Practical solutions to your common programming problems with Kotlin 1.1‱ Leverage the functional power of Kotlin to ease your Android application development‱ Learn to use Java code in conjunction with Kotlin Who This Book Is ForThis book will appeal to Kotlin developers keen to find solutions for their common programming problems. Java programming knowledge would be an added advantage.What You Will Learn‱ Understand the basics and object-oriented concepts of Kotlin Programming‱ Explore the full potential of collection frameworks in Kotlin‱ Work with SQLite databases in Android, make network calls, and fetch data over a network‱ Use Kotlin's Anko library for efficient and quick Android development‱ Uncover some of the best features of Kotlin: Lambdas and Delegates‱ Set up web service development environments, write servlets, and build RESTful services with Kotlin‱ Learn how to write unit tests, integration tests, and instrumentation/acceptance tests.In DetailThe Android team has announced first-class support for Kotlin 1.1. This acts as an added boost to the language and more and more developers are now looking at Kotlin for their application development. This recipe-based book will be your guide to learning the Kotlin programming language. The recipes in this book build from simple language concepts to more complex applications of the language. After the fundamentals of the language, you will learn how to apply the object-oriented programming features of Kotlin 1.1. Programming with Lambdas will show you how to use the functional power of Kotlin. This book has recipes that will get you started with Android programming with Kotlin 1.1, providing quick solutions to common problems encountered during Android app development. You will also be taken through recipes that will teach you microservice and concurrent programming with Kotlin. Going forward, you will learn to test and secure your applications with Kotlin. Finally, this book supplies recipes that will help you migrate your Java code to Kotlin and will help ensure that it's interoperable with Java.Style and approachThis book explains concepts related to Kotlin Programming using a practical approach and with the help of easy-to-follow recipes.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Kotlin Programming Cookbook est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Kotlin Programming Cookbook par Aanand Shekhar Roy, Rashi Karanpuria, Mitchell Wong Ho en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Informatica et Programmazione in Java. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2018
ISBN
9781788475211
Édition
1

Anko Commons and Extension Function

The following recipes will be covered in this chapter:
  • Setting up Anko with Gradle
  • Extending Android framework using extension function
  • Using extensions as properties
  • Using intents with Anko
  • Making a call intent using Anko
  • Sending a text intent using Anko
  • Browsing the web browser using Anko
  • Sharing some text using intents in Anko
  • Sending an email using Anko
  • Creating Android dialogs with Anko
  • Showing an alert dialog with a list of text items
  • Using Anko in Views
  • Logging using Anko
  • Handling dimensions with Anko
  • Version checking in Android

Introduction

Anko is a Kotlin library that was developed to make the Android development experience better. Kotlin itself makes Android development easier, and Anko is a cherry on top of it. With helpers for almost all common Android functionalities, Anko drastically reduces the amount of code you write and makes Android development fun.
Anko consists of several parts:
  • Anko Commons: It consists of helper methods for intents, dialogs, logging, and so on, which reduces the amount of code significantly.
  • Anko Layouts: With this library, you don't have to stick to conventional XML to create visual interfaces. Anko layout is a fast and type-safe way to write dynamic Android layouts.
  • Anko SQLite: This is a query DSL and parser collection for Android SQLite, which makes working with underlying SQLite database substantially easy.
  • Anko Coroutines: Coroutines are a great way to do asynchronous programming. Anko coroutines provide utilities based on the kotlinx.coroutines ( https://github.com/Kotlin/kotlinx.coroutines) library.
In this chapter, we will learn how to use Anko for Android development. So let's get started!

Setting up Anko with Gradle

We will begin by setting up the Anko library in our project. We will be using Gradle to handle the dependencies of the project.

Getting ready

I'll be using Android Studio to write code. You can also find the source code in the 1-setting-up-anko-with-gradle branch of repository at https://gitlab.com/aanandshekharroy/Anko-examples.

How to do it


Follow these steps to add Anko to your project using the Gradle build system:
  1. The easiest way to set up Anko with Gradle is do it by adding the following lines in your build.gradle file:
 compile "org.jetbrains.anko:anko:$anko_version"
  1. You can replace $anko_version with the latest version of Anko, which is 0.10.1 when this book was written.
  2. The preceding compile statement will add all available features (including Commons, Layouts, SQLite) into your project at once. If you don't want that, and would prefer adding them separately as needed, here are the compile statements:
  • anko-commons: This library contains a lot of helpers for Android SDK for Intents, Dialogs and Toasts, Logging, and Resource and Dimension:
 compile "org.jetbrains.anko:anko-commons:$anko_version"
  • Anko Layouts: Anko Layouts is a DSL for writing dynamic Android layouts:
compile "org.jetbrains.anko:anko-sdk25:$anko_version" // sdk15,19,21,23 are also available compile "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
  • anko-sqlite: This provides helpers for working with SQLite database:
compile "org.jetbrains.anko:anko-sqlite:$anko_version"
  • anko-coroutines: This library makes it easier to work with Kotlin coroutines:
compile "org.jetbrains.anko:anko-coroutines:$anko_version"

Extending Android framework using extension function

The heading of this recipe might seem very confusing to you as you might be thinking "How can I extend the super complex Android framework? And moreover, why should I?" We will be dealing with all the "what, why, and hows" of extension functions in this recipe. Extension functions are one of the greatest features of Kotlin. So let's dive into it.
2323__perlego...

Table des matiĂšres