Sign in

Mobile app developer, focusing on Android. Working at Brightec (www.brightec.co.uk). Links: www.github.com/alistairsykes www.twitter.com/SykesAlistair

The state of Android Camera: Tap to Focus

Tap to Focus

There’s no denying how satisfying it is when your camera magically knows what you’re pointing it at. But often it’s not quite right. So, we need the ability to focus the camera ourselves.

On Android, this is conventionally done using a tap. The user taps anywhere on the screen and the camera adjusts the lens to match.

Although the concept is simple, implementing this in your apps is rather tricky.

Camera1

When Android launched we had a relatively simple set of APIs. Implementing Tap to Focus went something like this.

Firstly, we have to add an onTouchListener. We listen for down…


How to use JAXB bindings with WSDL to separate schemas into different packages.

WSDL

As discussed in my previous blog, WSDL is an XML format that describes network services. It defines endpoints and their request and response formats.

WSDL files contain schemas to describe those request and response objects. A single WSDL file could contain multiple schemas. This is commonly used to share some objects between different network services. Such as to define some common types.

Example

You may have two WSDL files.

One describes a shopping service, and the other defines a checkout service. In the checkout service, you might buy things you shopped for. …


How and where to define your user-facing strings.

Messages.properties

You’ve probably already read about the messages.properties file. It allows you to define any strings you wish to present to an end-user.

messages.properties:

To retrieve one of these strings in code you first need to get a MessageSource. This is provided via spring dependency injection.

Constructor injection:

@Service // Or some other `Component` annotation
class SomeService( private val messageSource: MessageSource )

Property injection:

@Autowired private lateinit var messageSource: MessageSource

Then you can call getMessage:

messageSource.getMessage("title.example", null, LocaleContextHolder.getLocale())

args can be provided for string replacement. For example:

messageSource.getMessage("message.hello", arrayOf("Joe Bloggs"), LocaleContextHolder.getLocale())

Internationalization

Notice above, we pass LocaleContextHolder.getLocale() as a Locale to…


How to use JAXWS to generate HTTP client code using the Gradle Kotlin DSL.

WSDL

WSDL (Web Services Description Language) is an XML format. It describes network services, their endpoints and the corresponding request and response formats.

WSDL is commonly used in conjunction with a SOAP (Simple Object Access Protocol) API. Soap can be thought of as a way of structuring your API. Similar to what REST (REpresentational State Transfer) is.

WSDL File

Typically, the result of using WSDL is a .wsdl file. You may have multiple files, one for each service, and these can come in handy when trying to consume an API.

Since a .wsdl file describes exactly what the API looks like, you can…


Using the new and improved AnimatedVectorDrawable to pause and seek your animations.

AnimatedVectorDrawable

Android SDK 21 introduced both the VectorDrawable and the AnimatedVectorDrawable. This allowed you to use vector assets within your app, and even animate them.

They’ve iterated on these since then, but AnimatedVectorDrawable was still missing something. You couldn’t manipulate and control the animation. There was no pause or seek functionality.

Core-Animation

The Android team has been hard at work backporting the framework Animator APIs. They have created a separate unbundled AndroidX library called Core-Animation.

The Animator APIs have been around for some time. But they didn’t provide the capabilities needed for this pause and seek functionality. …


Educating Android users can be subtle by using motion

Material Design

The material design system will be familiar to most, as one of the most widely used design systems. It’s a visual language that represents good design principles whilst allowing expressive branding.

Foundationally, it is based on the physics of the world. This makes it natural and familiar to users. It models the way objects move and how they interact with each other.

Motion

Motion can celebrate the completion of a task, delight the user, or help to drive the user through a flow. The way objects move and interact can bring a touch of class and express your brand.

You can…


How to implement certificate pinning in Kotlin Multiplatform using Ktor

Certificate Pinning

Pinning certificates is a common practice when interacting with remote APIs. It is the act of constraining which certificates you trust. This helps to defend against attacks on certificate authorities. It also helps combat man-in-the-middle attacks.

There is a multitude of information available about certificate pinning. Here is some to get you started:

- https://owasp.org/www-community/controls/Certificate_and_Public_Key_Pinning

- https://labs.nettitude.com/tutorials/tls-certificate-pinning-101/

- https://docs.broadcom.com/docs/certificate-pinning-en

Kotlin Multiplatform

Kotlin Multiplatform (KMP) is a way of writing cross-platform code in Kotlin. It is not about compiling all code for all platforms, and it doesn’t limit you to a subset of common APIs. …


How does Kotlin Multiplatform affect your development culture?

Kotlin Multiplatform

Kotlin Multiplatform (KMP) is a way of writing cross-platform code in Kotlin. It is not about compiling all code for all platforms, and it doesn’t limit you to a subset of common APIs. KMP provides mechanisms for writing platform-specific implementations for a common API.

Culture

Culture is a big focus for many companies. We want to be in and build meaningful places to work. We want to be collaborative and make things better together.

However, we also like to feel part of a community. …


How to write tests within Kotlin Multiplatform

Testing

Code quality is very important, and testing is a huge part of code quality. You want to ensure the code you write behaves as expected. It also needs to work under a variety of conditions.

I use the Given When Then approach to testing across all our Small, Medium and Large tests. It’s a useful way of structuring tests. I also rely on mocking within my tests. I want to ensure the only thing I am testing is the class(es) I intended.

Kotlin Multiplatform

Testing within Kotlin Multiplatform is well supported and will feel very familiar.

implementation "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"

Kotlin provides…


How should you structure your multiplatform project?

Kotlin Multiplatform

Kotlin Multiplatform (KMP) is a way of writing cross-platform code in Kotlin. It is not about compiling all code for all platforms, and it doesn’t limit you to a subset of common APIs. KMP provides mechanisms for writing platform-specific implementations for a common API.

Android/iOS

One of the common use-cases, and indeed my main use-case, for KMP is to share code between an Android and iOS project.

Options

With KMP you have a few different options when it comes to deciding how to structure your projects.

You can combine your Android and iOS project into one project. They would live within the…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store