- 434 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Kotlin Programming Cookbook
About This Book
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.
Frequently asked questions
Information
Anko Commons and Extension Function
- 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 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.
Setting up Anko with Gradle
Getting ready
How to do itā¦
- 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"
- You can replace $anko_version with the latest version of Anko, which is 0.10.1 when this book was written.
- 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
Table of contents
- Title Page
- Copyright and Credits
- Packt Upsell
- Contributors
- Preface
- Installation and Working with Environment
- Control Flow
- Classes and Objects
- Functions
- Object-Oriented Programming
- Collections Framework
- Handling File Operations in Kotlin
- Anko Commons and Extension Function
- Anko Layouts
- Databases and Dependency Injection
- Networking and Concurrency
- Lambdas and Delegates
- Testing
- Web Services with Kotlin
- Other Books You May Enjoy