<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tim Rijckaert on Medium]]></title>
        <description><![CDATA[Stories by Tim Rijckaert on Medium]]></description>
        <link>https://medium.com/@timrijckaert?source=rss-a95d50081208------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*QB68OB6P6a9bznrL.jpg</url>
            <title>Stories by Tim Rijckaert on Medium</title>
            <link>https://medium.com/@timrijckaert?source=rss-a95d50081208------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 18:30:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@timrijckaert/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Publishing XCFrameworks to AWS CodeArtifact: A Complete Guide]]></title>
            <link>https://timrijckaert.medium.com/publishing-xcframeworks-to-aws-codeartifact-a-complete-guide-b3ef594bb9c7?source=rss-a95d50081208------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3ef594bb9c7</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <dc:creator><![CDATA[Tim Rijckaert]]></dc:creator>
            <pubDate>Wed, 13 Aug 2025 20:03:38 GMT</pubDate>
            <atom:updated>2025-08-13T20:06:19.935Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kDqrbsBmMN9L6OpmfL0BGA.jpeg" /></figure><p>Distributing iOS frameworks has always been challenging. While you can<br>generate XCFrameworks from various sources (Xcode projects, Kotlin<br>Multiplatform, React Native, etc.), getting them properly distributed to your<br>teams through a package registry requires jumping through several hoops.<br>Here’s how to package XCFrameworks as Swift Packages and publish them to AWS CodeArtifact.</p><p>While AWS CodeArtifact is used here it can be generalised to any other registry capable of maintaining Swift packages.</p><h3>Why We Moved Away from Git-Based Distribution</h3><p>Previously, we distributed our XCFrameworks by committing the built binaries directly to Git repositories.<br>This approach had several critical flaws:</p><p><strong>Repository bloat</strong>: <br>XCFrameworks can easily be 50–100MB or larger. <br>Each version adds to the repository size permanently, making clones extremely slow. A 50MB XCFramework becomes 500MB after just 10 releases.<br>Git isn’t designed for binaries: Git tracks every change to binary files as<br>complete new copies, leading to exponential growth rather than efficient delta storage.</p><p><strong>Privacy concerns:</strong> <br>Many teams don’t want to publish frameworks to public repositories, but managing private Git repos for binary distribution is cumbersome.</p><p><strong>Version management complexity:</strong> <br>Managing different versions meant either multiple branches/tags (messy), overwriting files (losing version history), or complex folder structures (confusing for consumers).</p><p><strong>Repository strategy debates:</strong> <br>Teams inevitably face the question:</p><blockquote><em>Do we create one repository per XCFramework, or dump everything into a single repository?”</em></blockquote><p>This creates a messy monolith like the <a href="https://github.com/CocoaPods/Specs">CocoaPods Specs repository</a>, where unrelated frameworks clutter the same repo:</p><pre>Specs/<br>├── Alamofire/<br>│   ├── 5.4.0/<br>│   ├── 5.4.1/<br>│   └── 5.4.2/<br>├── AFNetworking/<br>├── SDWebImage/<br>├── YourCompanyAuth/<br>│   ├── 1.0.0/<br>│   │   ├── YourCompanyAuth.podspec<br>│   │   └── YourCompanyAuth.xcframework<br>│   └── 1.1.0/<br>├── YourCompanyNetwork/<br>├── SomeOtherCompanyFramework/<br>└── ... (thousands of unrelated frameworks)</pre><p>This approach makes versioning, access control, and repository management nearly impossible when you have multiple teams contributing different frameworks.<br>Let alone private code.</p><p><strong>Consumer friction</strong>: <br>Teams had to use clunky Git-based dependencies:</p><pre>// Awkward Git-based approach<br>.package(url: &quot;https://github.com/company/private-framework.git&quot;, branch: &quot;v1.2.3&quot;)</pre><p>Instead of clean dependency declarations:</p><pre>dependencies: [<br>    .package(id: &quot;yourcompany.your-framework&quot;, from: &quot;1.2.3&quot;)<br>]</pre><h3><strong>The XCFramework Packaging Challenge</strong></h3><p>One frustrating aspect of publishing a XCFramework is that <strong>we have to wrap it in a Swift Packages just to distribute them</strong>.</p><p>This creates an awkward situation:</p><h4>What You Actually Have</h4><pre>MyFramework.xcframework/<br>├── ios-arm64/<br>├── ios-arm64_x86_64-simulator/<br>└── Info.plist</pre><h4><strong>What You’re Forced to Create</strong></h4><pre>MyFrameworkPackage/       # Artificial repository just for distribution<br>├── Package.swift         # Wrapper manifest<br>├── Sources/<br>│   └── File.swift        # Placeholder file<br>└── lib/<br>    └── MyFramework.xcframework/  # The actual binary</pre><p>Ideally, we should be able to directly depend on XCFrameworks and pull them from remote servers, but the current Swift Package Manager ecosystem requires this extra packaging step.</p><p>This means every XCFramework needs:</p><ul><li>A Package.swift manifest file</li><li>Proper directory structure</li><li>Swift Package metadata</li><li>Repository hosting (even for binaries)</li></ul><p>While cumbersome, this wrapper approach does provide version management and dependency resolution that wouldn’t exist with raw XCFramework distribution.</p><h3><strong>Creating Your XCFramework</strong></h3><p>XCFrameworks can be generated from various sources.</p><p>Here’s an example of our use case with Kotlin Multiplatform (though the distribution steps work regardless of how you generate your framework):</p><pre>// build.gradle.kts for KMP project<br>val xcframeworkName = &quot;YourFramework&quot;<br>val xcf = XCFramework(xcframeworkName)<br><br>listOf(<br>    iosArm64(),<br>    iosSimulatorArm64(),<br>    tvosSimulatorArm64(),<br>    tvosArm64()<br>).forEach {<br>    it.binaries.framework {<br>        baseName = xcframeworkName<br>        binaryOption(&quot;bundleId&quot;, &quot;com.yourcompany.${xcframeworkName}&quot;)<br>        xcf.add(this)<br>        isStatic = true<br>    }<br>}</pre><p>Build the XCFramework:</p><pre>./gradlew assembleYourFrameworkXCFramework</pre><p>This generates `YourFramework.xcframework` in `build/XCFrameworks/release/`.</p><blockquote><em>Note: This is just one example of XCFramework generation. The publishing process described in this guide works regardless of how you create your XCFramework — whether from Xcode projects, React Native, or other methods.</em></blockquote><h3><strong>Swift Package Wrapper Setup: A Necessary Evil</strong></h3><p>Create the proper directory structure for your Swift Package. This is crucial. The structure must be exactly right:</p><pre>swift-package/<br>├── Package.swift<br>├── Sources/<br>│   └── File.swift          # Placeholder file (required!)<br>└── lib/                    # Directory for your XCFramework<br>    └── YourFramework.xcframework/</pre><p><strong>You need the `Sources/` directory with at least one Swift file, even if it’s empty.**</strong> Without this, Swift Package Manager will fail silently ¯\_(ツ)_/¯:</p><pre>// File.swift - Placeholder to keep SwiftPM happy</pre><p>Create your Package.swift with the essential binaryTargetconfiguration:</p><pre>// swift-tools-version: 5.10<br>import PackageDescription<br><br>let package = Package(<br>    name: &quot;YourFramework&quot;,<br>    products: [<br>        .library(<br>            name: &quot;YourFrameworkLibrary&quot;,<br>            targets: [&quot;YourFrameworkLib&quot;, &quot;YourFrameworkWrapper&quot;]<br>        ),<br>    ],<br>    targets: [<br>        .target(<br>            name: &quot;YourFrameworkWrapper&quot;,<br>            path: &quot;Sources&quot;,<br>            linkerSettings: [<br>                .linkedFramework(&quot;YourFramework&quot;)<br>            ]<br>        ),<br>        .binaryTarget(<br>            name: &quot;YourFrameworkLib&quot;,<br>            path: &quot;lib/YourFramework.xcframework&quot;<br>        )<br>    ]<br>)</pre><p>The binaryTarget pointing to your XCFramework path and the linkerSettings with linkedFramework are both essential. <br>Omit either of these and Xcode will silently skip linking your XCFramework, leading to confusing runtime crashes.</p><h3><strong>AWS CodeArtifact Configuration</strong></h3><p>This guide assumes you already have a CodeArtifact domain and Swift repository set up. If you need help with the initial AWS setup, refer to the <a href="https://docs.aws.amazon.com/codeartifact/latest/ug/get-set-up-for-codeartifact.html">official CodeArtifact documentation</a>.</p><h4><strong>Publishing Process</strong></h4><p>Based on real-world experience, here’s what actually works for publishing to CodeArtifact:</p><h4><strong>Step 1: Copy XCFramework to Package Structure</strong></h4><pre># Copy your built XCFramework to the Swift package lib directory<br>cp -R build/XCFrameworks/release/YourFramework.xcframework swift-package/lib/</pre><h4><strong>Step 2: Navigate to Package Directory and Authenticate</strong></h4><p>Execute these commands in the directory containing Package.swift</p><pre>cd swift-package<br><br># Get CodeArtifact token<br>export CODEARTIFACT_AUTH_TOKEN=$(aws codeartifact get-authorization-token \<br>    --domain your-domain \<br>    --domain-owner 123456789012 \<br>    --region your-region \<br>    --query authorizationToken \<br>    --output text)<br><br># Set registry (must be run from Package.swift directory)<br>REGISTRY_URL=&quot;https://your-domain-123456789012.d.codeartifact.your-region.amazonaws.com/swift/your-repo&quot;<br>swift package-registry set &quot;${REGISTRY_URL}/&quot;</pre><h4><strong>Step 3: Create Archive and Upload</strong></h4><p>We know the swift package-registry publish command exists but it failed for us.</p><p>It didn’t include the Authorizationheader properly. The cURL approach is simpler and more reliable.</p><p>Rely on the swift package archive-sourceto create the archive.<br>This ensures the archive format is correct for distribution.</p><pre># Create the archive (generates YourFramework.zip)<br>swift package archive-source<br><br># Upload directly via HTTP<br>curl -X PUT \<br>    --user &quot;aws:${CODEARTIFACT_AUTH_TOKEN}&quot; \<br>    -H &quot;Accept: application/vnd.swift.registry.v1+json&quot; \<br>    -F &quot;source-archive=@YourFramework.zip&quot; \<br>    &quot;${REGISTRY_URL}/yourcompany/your-framework/1.0.0&quot;</pre><h3><strong>Consuming the Published Framework</strong></h3><p>Before teams can use your published framework, they need to authenticate with CodeArtifact.</p><h4><strong>Step 1: Authentication Script</strong></h4><p>We create a simple script to handle authentication and registry setup for teams consuming your framework. This script retrieves the CodeArtifact authorization token and configures the Swift Package Manager to use your CodeArtifact repository.</p><pre>#!/bin/bash<br><br>set -e<br><br>CODEARTIFACT_DOMAIN=&quot;your-domain&quot;<br>CODEARTIFACT_DOMAIN_OWNER=&quot;123456789012&quot;<br>CODEARTIFACT_REGION=&quot;your-region&quot;<br>CODEARTIFACT_REPOSITORY=&quot;your-repo&quot;<br>CODEARTIFACT_REGISTRY_URL=&quot;https://${CODEARTIFACT_DOMAIN}-${CODEARTIFACT_DOMAIN_OWNER}.d.codeartifact.${CODEARTIFACT_REGION}.amazonaws.com/swift/${CODEARTIFACT_REPOSITORY}/&quot;<br><br># Get authentication token<br>CODEARTIFACT_AUTH_TOKEN=$(aws codeartifact get-authorization-token \<br>    --domain ${CODEARTIFACT_DOMAIN} \<br>    --domain-owner ${CODEARTIFACT_DOMAIN_OWNER} \<br>    --region ${CODEARTIFACT_REGION} \<br>    --query authorizationToken \<br>    --output text)<br><br>if [ -z &quot;$CODEARTIFACT_AUTH_TOKEN&quot; ]; then<br>    echo &quot;Failed to get CodeArtifact authorization token.&quot;<br>    exit 1<br>fi<br><br>echo &quot;Setting Swift package registry...&quot;<br>swift package-registry set &quot;${CODEARTIFACT_REGISTRY_URL}&quot; --scope yourcompany<br><br>echo &quot;Logging in to package registry...&quot;<br>swift package-registry login &quot;${CODEARTIFACT_REGISTRY_URL}login&quot; --token &quot;${CODEARTIFACT_AUTH_TOKEN}&quot;<br><br>echo &quot;Authentication complete. You can now run &#39;swift package resolve&#39; or build your project.&quot;</pre><p>Teams run this authentication script once every time they need to authenticate with CodeArtifact.</p><p>The token is valid for 12 hours, so they can reuse it during that period without needing to re-authenticate.</p><h4><strong>Step 2: Use in Package.swift</strong></h4><p>After authentication, teams can use your framework with clean dependencies:</p><pre>// swift-tools-version: 6.1<br>import PackageDescription<br><br>let package = Package(<br>    name: &quot;MyLibrary&quot;,<br>    platforms: [<br>        .iOS(.v13)<br>    ],<br>    products: [<br>        .library(<br>            name: &quot;MyLibrary&quot;,<br>            targets: [&quot;MyLibrary&quot;]),<br>    ],<br>    dependencies: [<br>        .package(id: &quot;yourcompany.your-framework&quot;, exact: &quot;1.0.0&quot;)<br>    ],<br>    targets: [<br>        .target(<br>            name: &quot;MyLibrary&quot;,<br>            dependencies: [<br>                .product(name: &quot;YourFrameworkLibrary&quot;, package: &quot;yourcompany.your-framework&quot;)<br>            ]<br>        ),<br>    ]<br>)</pre><h4><strong>Step 3: Build and Resolve</strong></h4><p>Once authenticated and with the Package.swift configured, normal Swift Package Manager commands work:</p><pre>swift package resolve<br>swift build</pre><h3>Conclusion</h3><p>Documentation for publishing Swift packages to CodeArtifact is surprisingly sparse. While AWS provides better documentation than what’s available from Apple or Swift sources, Swift-specific guidance is still minimal and often incomplete. The official Swift Package Manager documentation barely touches on private registries, leaving developers to piece together solutions from scattered forum posts and trial-and-error.</p><p>This gap in documentation is particularly frustrating when it comes to the specific requirements for structuring Swift packages with embedded XCFrameworks. The critical details — like needing a Sources/ directory with placeholder files, the exact binaryTarget configuration, and the authentication quirks with CodeArtifact - are nowhere to be found in official guides.</p><p>I wrote this blog post because it took me considerable time to get this setup working correctly. Too many hours were spent debugging silent failures, wrestling with authentication issues, and discovering undocumented requirements the hard way. If this guide saves even one developer from that same frustration, the effort was worthwhile.</p><p>The Swift ecosystem’s approach to binary distribution feels unnecessarily complex compared to other platforms, but with the right configuration and workflow, CodeArtifact does provide a solid solution for private framework distribution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3ef594bb9c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compose Component Builders]]></title>
            <link>https://timrijckaert.medium.com/compose-component-builders-74e76b63c5ee?source=rss-a95d50081208------2</link>
            <guid isPermaLink="false">https://medium.com/p/74e76b63c5ee</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Tim Rijckaert]]></dc:creator>
            <pubDate>Sat, 17 Sep 2022 16:48:56 GMT</pubDate>
            <atom:updated>2022-09-18T09:14:43.149Z</atom:updated>
            <content:encoded><![CDATA[<h4>A story of how we went from a dozen of overloads to just one Composable function.</h4><h3>The issue</h3><p>Since we have started working with Compose it became clear we had a need to share some Composables across multiple features in our app.</p><p>We created an Android library module in our project dedicated to host these shared Composables.</p><p>One such popular shared Composables we have in the project is what we internally refer to as an IllustratedInfo.</p><p>It’s a full screen Composable, that we use to convey a variety of information to the end user. Ranging from information text, warnings to errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*qaDVh6epgWSQMSSfHdESLw.jpeg" /><figcaption>An example of the `IllustratedInfo` component</figcaption></figure><p>The structure we got from the designer is pretty self explanatory.<br>From top to bottom:</p><ul><li>An image</li><li>A title</li><li>A description</li><li>A subtitle</li><li>A sub-description</li><li>Bulletpoint(s)?</li><li>Button(s)?</li></ul><p>We thought about how we could model this nicely in Compose and we quickly found a few problems:</p><ul><li>The component is <strong>text heavy</strong>; How do we make sure we don’t end up with multiple overloads for different types that can represent text in Android?</li><li>Not all components should/can be present all the time.<br>Do we model these as <strong>nullable arguments</strong>?<br>For example the <em>subtitle</em> and <em>sub-descriptions</em> can be empty in which case they should not be rendered.</li><li>We can <strong>not hard code the positions of the elements</strong>.<br>What if the designer wants to have the <em>bullet-points</em> after the description, whilst still maintaining the ability to add a <em>subtitle</em> and a <em>sub-description </em>?</li><li>How <strong>extensible</strong>/<strong>scalable</strong> is this component?<br>What if we need to add another kind of element, do we have to update multiple signatures/overloads?</li></ul><p>Let’s go over the steps we took to create an elegant API for the IllustratedInfo.</p><h3>Text in Compose</h3><p>In Compose we have different types that represent <em>text to be rendered on screen</em>.</p><p>– We obviously have String<br> – We have an Int that refers to a String resource<br>– We have an AnnotatedString</p><p>If we look at the source code of the Text Composable of Android we see they provide two overloads.<br>One for a String and one for an AnnotatedString.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pnhemBK5LANiJoVSJAkGcA.jpeg" /></figure><p>In the context of the IllustratedInfo this would mean we would have to provide following overloads:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pZFWyc2CO7SEVYv1teSlfQ.jpeg" /></figure><p>We quickly noticed this does not play nicely when working with string resources. So we saw the need to add a third overload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1dtXG-rst8chR3pGopewqg.jpeg" /></figure><p>Even with these three overloads we did not cover all cases. <br>What if you have a mixture of different types?<br>What if the title and subtitle are String resources but the descriptions are Strings.</p><p>Of course you could deal with this <em>shortcoming</em> and use the stringResource function and redirect to the IllustratedInfo with the String overloads.<br>It is however a lot more clumsy to do the same if one of the arguments is an AnnotatedString.</p><p>On top of this the IllustratedInfo component is not the only shared component with this particular problem. <br>So we need a more robust solution.</p><p>We resolved this by making a wrapper type around Int , String and AnnotatedString . For a lack of a better name lets call it Text .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZVQYRNuz1OYqxS4AhanHnQ.png" /></figure><p>By wrapping the Text Composable we brought the flexibility of bringing back our overloads to just one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*X6whaiOo9FGbv-N4H5t_-A.png" /></figure><p>We can now mix and match different types.<br>To ease the wrapping we can provide some helper extension functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*MomCg6mIj02bH8iWV0uuuA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R8q_CCbKbIoBojq8XSjFWw.png" /></figure><h3>Nullable arguments?</h3><p>So far we assumed all arguments are required. <br>However the designer wants to have full freedom to design this screen and thus we decide to make everything optional.<br>In the code this could translate to making every argument nullable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*JX5zuSyJ181_UQE_4ZR9sQ.png" /></figure><p>However, should it be possible to create an IllustratedInfo</p><ul><li>with a <em>subtitle</em>, but without a <em>sub-description?</em></li><li>with a <em>button, </em>but without a click listener?</li><li>with all fields set to null</li></ul><p>We certainly allow it in the above method signature.<br>However they would yield wrong results and we should prevent developers from making these mistakes.</p><p>But how can we do this without again reverting to multiple method overloads?</p><h3>Slot API’s?</h3><p>Another issue we still have to tackle is how do we allow:</p><ul><li>multiple <em>subtitles</em></li><li>render the list of <em>bulletpoints </em>above the <em>subtitle</em></li></ul><p>Slot API’s are described on the <a href="https://developer.android.com/jetpack/compose/layouts/basics#slot-based-layouts">Android developer</a> as:</p><blockquote>… a pattern Compose introduces to bring in a layer of customization on top of Composables. This approach makes components more flexible, as they accept a child element which can configure itself rather than having to expose every configuration parameter of the child. Slots leave an empty space in the UI for the developer to fill as they wish. For example, these are the slots that you can customize in a <a href="https://material.io/components/app-bars-top">TopAppBar</a>:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F4_Cp5Elj9stamkGgw5_qg.png" /><figcaption>The TopAppBar which works with the Slot API</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sAx259Kx9cPCCIQ0uYN7kA.jpeg" /><figcaption>Does it make sense to use Slots for the IllustratedInfo component?</figcaption></figure><p>We could divide our Composable into seven slots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kVuzusMkkOC56S_t7mp_Eg.png" /></figure><p>This way the developer has full control over what they want to render where.<br>With this change we can finally render the list of <em>bulletpoints </em>before the <em>subtitle</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YDNBhf7M3BiDu3I2hCFQgA.png" /></figure><p>Inadvertently by making the IllustratedInfoAPI so flexible we allow even more potential misuse:</p><ul><li>The developers can insert any Composable in any of the slots.</li><li>Furthermore the IllustratedInfoAPI has become complex to use. <br>Developers need to know which <em>slot</em> they need to populate.<br>As a shared component it is impossible to provide a good argument name for the slots as you don’t want to enforce what elements it can/should accept.</li><li>We have to expose the previously <em>private </em><em>Composable`s </em>IllustratedTitle , IllustratedInfoImage , …</li><li>The IllustratedInfo becomes an empty shell and there is no use for it anymore. It has become a very limited implementation of a Column</li></ul><p>Slot API’s are very helpful when your component has some <strong>fixed </strong>reserved spaces where the developer can put <strong>any</strong> Composable.<br>In our case the slots are ‘<em>dynamic</em>’.<br>Plus we don’t want the developer to be able to put <strong>any</strong> Composable inside the IllustratedInfo , the options are limited to the list we got from the designer.</p><p>But how?</p><h3>Extensible/Flexible</h3><p>Lastly before we look at our solution, let’s look how easy it is to add new kind of type to the IllustratedInfo .<br>Our designer comes to us telling us we need to be able to add a link to the IllustratedInfo .<br>(Based on a true story)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*7URGLkkQQDCxxXG2lBVtWg.png" /></figure><p>Easy right?<br>But where do we render this link?<br>What if we need to render multiple links? Do we add even more optional arguments? link1 , link2 , …?<br>Each type would require at least 1 argument in the already big list of arguments for the IllustratedInfo .</p><h3>Builder pattern to the rescue</h3><p>What we want to achieve:</p><ul><li>Flexible; The developer should be able to tell where a component should be rendered</li><li>Extensible; It should be easy to add a new kind of Composable to the list of supported elements an IllustratedInfo</li><li>Prevent wrong combinations of arguments; Such as a button without a click listener.</li></ul><p>To achieve this we use the builder pattern as it lends itself well to fulfill these requirements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*2HAHN7dkF-qQtnaZfzXS2Q.png" /></figure><p>For each element our IllustratedInfo we create a method in our builder.</p><p>The sharp eyed amongst us will have noticed I no longer have a <em>sub-description </em>method.<em><br></em>Since the <em>description</em> and <em>sub-description</em> are rendered both in the same way, there was no more need to make a distinction.</p><p>By grouping arguments that belong together such as the <em>btnText </em>and the <em>onClick, </em>we prevent wrong combinations of arguments.</p><p>We also gain the ability to call builder functions multiple times, which results in the elements rendered multiple times.</p><p>The implementation of the IllustratedInfoBuilder is pretty straightforward</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tvVa_jxiN_aeC8wpss0gLQ.png" /></figure><p>The IllustratedInfoItem is a sealed class with all the possible elements the IllustratedInfo supports.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*3fRU6EZLEtRg_nOvrKCBtA.png" /></figure><p>We can refactor the IllustratedInfo function one last time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jpK1-mzgRcuD_LIvz-a6YA.png" /><figcaption>The implementation of the individual Composables has been left out for brevity and simplicity</figcaption></figure><p>Thanks to the Kotlin syntax of putting the IllustratedInfoBuilder as the last parameter, our IllustratedInfo now functions like a DSL.<br>Where the builder methods are only available in scope of the IllustratedInfoBuilder</p><p>Note that by leveraging on a List as our backing data structure in the IllustratedInfoBuilder we add an implicit requirement that calls to builder functions should happen in the order they should be rendered in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EjDN1if053_B6lVtuyGeng.png" /><figcaption>Sample usage of the builder API, The order in which the items are declared is the order in which they will appear on screen.</figcaption></figure><h3>Bonus: Composing Component builders</h3><p>As you are building more reusable Composable components you will find it helpful to split up Composable s into smaller pieces so they become easier to re-use in other Composables.</p><p>In the case of this example we took the button as part of the IllustratedInfo however you might want this to be a different component all together.<br>In our case we have such a component. <br>It is able to render buttons in different orientations (vertical, horizontal), containing just one primary button or a combination of a primary with a secondary and/or tertiary button.<br>We call this component the ButtonContainer .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*spyw5zOPu1BYUkcWguZAAA.png" /><figcaption>ButtonContainer rendering the buttons in a vertical orientation</figcaption></figure><p>Similar to the IllustratedInfoBuilder it has an associated builder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bE9bnUvUWv55-XdtDarTyw.png" /></figure><p>Ideally we wish to <strong>reuse</strong> the ButtonContainerBuilder in the IllustratedInfoBuilder in a similar way to how the Slot API’s work.<br>We could say we want to <em>compose</em> both the ButtonContainer Composable and the IllustratedInfo Composable to create one new Composable .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L94n5vhEwA__g25GumQjPQ.jpeg" /></figure><p>To achieve this we can inherit from the ButtonContainerBuilder in the IllustratedInfoBuilder and by the magic of delegation in Kotlin we forward the implementation details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*phGsoPWXJ1N8kVC4lT6O-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G_rNGBwFdtHgZn1JMrulLA.png" /></figure><p>Note we also removed the now redundant button function from the IllustratedInfoBuilder.</p><p>We now adjust the IllustratedInfo composable once more 🙈<br>And forward the ButtonContainerConfiguration to the ButtonContainer Composable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U50J0Cu9XBrRD1FuE_mnVQ.png" /></figure><p>Now we also have access to all the method defined in the ButtonContainerBuilder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hUxv2WFO-sDwM9910WghZw.png" /></figure><p>Thanks for reading this very lengthy article, I hope this inspired to think about how you can split up your lengthy Composable s.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74e76b63c5ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How we made our UI tests more stable with MockK and Dexopener]]></title>
            <link>https://proandroiddev.com/how-we-made-our-ui-tests-more-stable-with-mockk-and-dexopener-c78b02a86de?source=rss-a95d50081208------2</link>
            <guid isPermaLink="false">https://medium.com/p/c78b02a86de</guid>
            <category><![CDATA[espresso]]></category>
            <category><![CDATA[dexopener]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Tim Rijckaert]]></dc:creator>
            <pubDate>Tue, 25 May 2021 13:50:25 GMT</pubDate>
            <atom:updated>2021-05-30T10:08:38.598Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jWm7jZ77byiefswi-YGbsw.gif" /></figure><h3>How to mock under instrumentation test with MockK and Dexopener</h3><h3>Problem</h3><p>At my current client we have been heavily investing in UI tests. <br>We make extensive use of <a href="https://firebase.google.com/products/test-lab">Firebase TestLab</a> to run our instrumented tests twice a day.</p><p>Until recently we ran our UI tests without the need for any mocking.<br>This also meant we have huge maintenance to keep the pipeline green 🟢.<br>In our effort to keep the benefits of UI tests while at the same time increase the stability, we converted a big chunk of our test cases to <a href="https://developer.android.com/guide/fragments/test">test fragments in isolation</a>.</p><p>Since we have good experiences using <a href="https://mockk.io/">MockK</a> for our unit tests we decided to use the <a href="https://mockk.io/#gradlemaven-dependency">Android-MockK</a> dependency for our instrumented tests.</p><p>When running the tests locally they passed but, running them on Firebase they consistently failed with the following cryptic stack trace:</p><pre>io.mockk.MockKException: Missing calls inside verify { ... } block.<br>at io.mockk.impl.recording.states.VerifyingState.checkMissingCalls(VerifyingState.kt:52)<br>at io.mockk.impl.recording.states.VerifyingState.recordingDone(VerifyingState.kt:21)<br>at io.mockk.impl.recording.CommonCallRecorder.done(CommonCallRecorder.kt:47)<br>at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:60)<br>at io.mockk.impl.eval.VerifyBlockEvaluator.verify(VerifyBlockEvaluator.kt:30)<br>at io.mockk.MockKDsl.internalVerify(API.kt:118)<br>at io.mockk.MockKKt.verify(MockK.kt:149)<br>at io.mockk.MockKKt.verify$default(MockK.kt:146)<br>at com.example.our.app.OurUITest.method(OurUITest.kt:75)</pre><p>This trace didn’t make any sense since we were using a mock inside the verify block. Hence why it worked locally. 🤔<br>But why did it <strong>not</strong> work on Firebase testlab?</p><p>We use this script to launch our UI tests on Firebase.</p><pre>gcloud firebase test android run \<br>  --app testlab/build/outputs/apk/debug/testlab-debug.apk \<br>  --test $MODULE_PATH/build/outputs/apk/androidTest/debug/*.apk \</pre><p>By default when you don’t select a specific device/emulator it will use a Pixel 2 with API 27. Comparing the default Firebase configuration we noticed the API level was different from our local emulator, which was using API 29.<br>Luckily we can specify the API level in the <em>gcloud</em> command.</p><pre>gcloud firebase test android run \<br>  --app testlab/build/outputs/apk/debug/testlab-debug.apk \<br>  --test $MODULE_PATH/build/outputs/apk/androidTest/debug/*.apk \<br>  <strong>--device version=29,model=Pixel2</strong></pre><p>When we ran our test on Firebase with API 29 the tests started passing again.</p><p><strong>Why</strong>? 🤔<br>And <strong>how can we make our instrumented tests run on lower API levels</strong>? 🤔</p><h3>A-ha moment</h3><p>Turning to Google yielded an <a href="https://github.com/mockk/mockk/issues/182">open feature request (#182) </a>on the MockK issue board. Turns out mocking on the JVM is entirely different than mocking during instrumentation.<br>What’s more, is the ability to mock final classes during instrumented tests is dependent on the API level you are running.</p><p>Just like every modern Android codebase, we adopted Kotlin as our programming language of choice for Android Development. <br>By default every Kotlin class you create is final by default.</p><p>It is even mentioned in the <a href="https://mockk.io/ANDROID.html">MockK documentation</a></p><blockquote>Implementation is based on <a href="https://github.com/linkedin/dexmaker">dexmaker</a> project. With Android P, instrumentation tests may use full power of inline instrumentation, so object mocks, static mocks and mocking of final classes are supported. Before Android P, only subclassing can be employed, so you will need the ‘all-open’ plugin.</blockquote><p>Verifying this we can indeed see that io.mockk:mockk-android is using dexmaker. Which is capable of generating .dex files at runtime.</p><pre>+--- io.mockk:mockk-android:1.10.6<br>    +--- org.jetbrains.kotlin:kotlin-stdlib:1.5.0<br>    +--- io.mockk:mockk:1.10.6<br>    +--- io.mockk:mockk-agent-android:1.10.6<br>    |    +--- <strong>com.linkedin.dexmaker:dexmaker:2.21.0</strong><br>    |    \--- org.objenesis:objenesis:2.6<br>    \--- io.mockk:mockk-agent-api:1.10.6</pre><p>Unfortunately, we can not use the dexmaker library for lower API versions.</p><blockquote>This functionality requires OS APIs which were introduced in Android P and cannot work on older versions of Android.</blockquote><p>If we wish to enable mocking support for lower API levels we have two options:</p><ul><li>Kotlin all-open plugin</li><li>DexOpener</li></ul><p>You can read more about Kotlin all-open plugin in <a href="https://proandroiddev.com/mocking-androidtest-in-kotlin-51f0a603d500">this blogpost</a> as we’ll be focusing on using DexOpener in this blogpost.</p><h4>DexOpener to the rescue</h4><p><em>If you want to skip ahead; </em><a href="https://github.com/timrijckaert/dexopener_sample"><em>I created a dummy project where you can see a full implementation of the DexOpener library.</em></a></p><p>DexOpener describes themselves as:</p><blockquote>An Android library that provides the ability to mock your final classes on Android devices.</blockquote><p>Exactly what we need!<br>Adding the dependency is easy.</p><p>Add https://jitpack.io to your repositories block</p><pre>allprojects <strong>{<br>    </strong>repositories <strong>{<br>        maven { url &#39;https://jitpack.io&#39; }<br>        </strong>google()<br>        mavenCentral()<br>        jcenter()<br>    <strong>}<br>}</strong></pre><p>Add the dependency itself to the module.</p><pre>androidTestImplementation<strong> &#39;com.github.tmurakami:dexopener:2.0.5&#39;</strong></pre><p>Inside your package under the androidTest directory add a new class DexOpeningTestRunner .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d878b27427d0407032a942181d55b338/href">https://medium.com/media/d878b27427d0407032a942181d55b338/href</a></iframe><p>As you can see from the code, we only activate DexOpener when we detect that we are running on &lt; Android P since MockK will use DexMaker for higher API levels.</p><p>The last step is to enable our custom instrumentation runner in the build.gradle</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4f68a12b48d73c6b1494263d4a25bca/href">https://medium.com/media/d4f68a12b48d73c6b1494263d4a25bca/href</a></iframe><h4>Bonus Multi-module</h4><p>What might not be immediately obvious is the package directive of the custom testrunner is very important to be placed correctly.</p><p>Consider you have a multi-module project, you probably want to share this test runner with other modules.<br>In which case you will have to ensure the DexOpeningTestRunner is placed in a package used by all the modules.</p><p>You can find <a href="https://github.com/timrijckaert/dexopener_sample">a full demo project on Github</a>.</p><p>Happy testing</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c78b02a86de" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/how-we-made-our-ui-tests-more-stable-with-mockk-and-dexopener-c78b02a86de">How we made our UI tests more stable with MockK and Dexopener</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Yee-haw Cowboy3 ]]></title>
            <link>https://timrijckaert.medium.com/cowboy3-experience-a57decaf991f?source=rss-a95d50081208------2</link>
            <guid isPermaLink="false">https://medium.com/p/a57decaf991f</guid>
            <category><![CDATA[bicycles]]></category>
            <category><![CDATA[electric]]></category>
            <category><![CDATA[e-bike-market]]></category>
            <category><![CDATA[cowboys]]></category>
            <dc:creator><![CDATA[Tim Rijckaert]]></dc:creator>
            <pubDate>Mon, 12 Oct 2020 16:26:18 GMT</pubDate>
            <atom:updated>2020-10-12T19:06:57.501Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p>I switched work recently. <br>Fortunately for me it was close to a train station so I decided to go by train from now on. <br>To get to the nearest train station (which is only 3km) I decided to buy a bike.</p><p>Since I’m a (bit of a) nerd 🤓 , I didn’t just want <em>a bike</em> I wanted an e-bike! <br>Most e-bikes look like a hot mess; a normal bike with a lumpish battery attached to the luggage carrier. <br>We all know them, these <em>un-inspirational</em> bikes you only see elderly people drive.</p><h3>Biggest Competitor — VanMoof</h3><p>In my search for a good looking e-bike I considered 2 options.<br>The Belgian <a href="https://cowboy.com/">Cowboy</a> and the Dutch <a href="https://www.vanmoof.com/">VanMoof</a>.</p><p>Both recently released their latest models to the world.<br>The <strong>Cowboy 3</strong> and the <strong>VanMoof S3/X3</strong>.</p><p>Both look stunning and both come with a high nerd factor.<br>Aiming for the younger always connected generation.<br>Both require you to use an app on your phone to unlock.</p><p>Both have similar price points:<br>(Prices are at the time of writing in Belgium)</p><ul><li>The Cowboy starts at <strong>€2.290</strong>.</li><li>The VanMoof starts at <strong>€1.998</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j53rhK-qkOj4X7gsZZAuJA.gif" /></figure><p>Both have different colour options.<br>You can choose from 3 colours with the Cowboy:</p><ul><li>Absolute Black</li><li>Anthracite Grey</li><li>Mineral Grey</li></ul><p>And 2 colour options with the VanMoof:</p><ul><li>Sky Blue</li><li>Deep Gray Black</li></ul><p>Both are stunning and are a real head turner.</p><p>Both are equipped with a GPS system.<br>Handy to automatically save your bike rides and locate it in case it’s stolen.</p><p>Both have a 250W motor assisting you to a maximum of 25km/h.</p><p>Both frames are made out of aluminium. With the Cowboy weighing in at 17kg and the VanMoof 19kgs.</p><p>Both can optionally be extended with a theft insurance. <br>Reimbursing you when the bike gets stolen. <br>VanMoof even goes one step further and actively searches your bike if it gets stolen. If they can’t retrieve it within 2 weeks you get a new one free of charge.<br>You can even watch their progress for the hunt of stolen bikes on <a href="https://www.youtube.com/watch?v=SrT4inIxK0g&amp;ab_channel=VanMoof">Youtube</a>.</p><p>Even though they are very similar they do have their differences:</p><p>Despite the VanMoof being slighter cheaper than the Cowboy, it comes in a more feature complete package.<br>You get mudguards and a kickstand included.<br>Whereas the Cowboy comes with neither as standard. <br>Though mudguards can be factory installed for an extra <strong>€89.<br></strong>If you know someone who already owns a Cowboy you can use the <a href="https://share.cowboy.com/r/timri">referral link</a>, and get them for free. (I attached mine in the link)</p><p>The Cowboy has a belt drive instead of the traditional chain drive found on the VanMoof. A belt drive is supposed to be more maintenance friendly and best of all no dirty hands when touching them.</p><p>The VanMoof has a delivery date of 7–10 weeks whereas the Cowboy delivers the Absolute Black version of the bike in 21 days to your doorstep.</p><p>The VanMoof has a bigger battery giving you a range between 60–150km.<br>The Cowboy gives you 70km of range.<br>However the battery from the VanMoof is built in to the frame of the bike and is not easily removable. <br>Charging the VanMoof requires you to plug in the bike to an outlet.<br>The Cowboy makes this much easier by allowing you to charge the battery separately.</p><p>But perhaps the biggest difference is the way how they deliver their power to the wheels.<br>VanMoof uses a front wheel motor. The Cowboy delivers the power like any traditional bike to the rear wheel. <br>In slippery situations a rear wheel motor will prove to be easier and safer to control. Not so unimportant in cold rainy Belgium.</p><p>VanMoof’s keyword is <strong>comfort</strong> compared to <strong>hard and sporty</strong> for the Cowboy.<br>You can tell by the horizontal handlebars versus the thicker and curved handlebar from the VanMoof.<br>The saddle from the VanMoof is mushier compared to the p̶l̶a̶n̶k̶ saddle you get on the Cowboy.</p><p>The Cowboy is <em>smarter</em>, providing you the power when you want/expect it.<br>It does this by measuring the force exert on the pedals.<br>The more force, the more the motor will assist you.<br>The result of this is a very smooth power delivery without any jarring effect found on other e-bikes.</p><p>VanMoof uses 4 power levels delimited by the current speed you are driving.<br>Automatically switching to the correct one (you can adjust the gear switching in the app to your liking).<br>Cowboy only has 1 gear ratio.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*lOll8N8Wo_Mm7MiazcLCaQ.gif" /><figcaption>VanMoof automatic gear switcher</figcaption></figure><h3>Test ride</h3><p>Before fully deciding I wanted to test for myself.<br>Luckily Cowboy provides test drives.<br>You can <a href="https://cowboy.com/pages/test-ride">schedule a test ride</a> online.<br>A local Cowboy 🤠 will drive a test Cowboy to your house.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qOQ3axwB3UgzTvTxe2QyXA.jpeg" /><figcaption>A late night test drive with the Cowboy. This was a Cowboy2</figcaption></figure><p>This is in sheer contrast to VanMoof only offering test drives at their Pop-up Store in Brussels.</p><p>My first experience with the Cowboy was ❤️ at first sight.<br>The sales guy also gave ample information and honest feedback on his experience with his Cowboy.<br>Turns out the same person will also be your first line local support for anything technical.</p><p>I would definitely recommended the test drive if you are still unsure.</p><p>Ultimately I decided to go with the <strong>Cowboy </strong>over the VanMoof because of:</p><ul><li>Smooth drive powering the correct wheel</li><li>Exchangeable battery</li><li>Shorter delivery time</li><li>Closer to home if something were to go wrong. 🇧🇪</li></ul><p>That night my decision was made and I order the <strong>Absolute Black</strong> <strong>with mudguards</strong> for a grand total of <strong>€2,379</strong></p><h3>Delivery — Initial installation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PtPNjOyxl-UlNuPkz3SGxg.jpeg" /><figcaption>The bike comes in a huge box</figcaption></figure><p>I ordered 🤠 4 september and it arrived 30 september. <br>When I ordered mine the delivery time was estimated on 31 days, now it has shortened to just 21days for the Absolute Black colour option.</p><p>Small point of criticism the delivery partner did not sent a delivery confirmation. Resulting in a sudden drop off at my doorstep, luckily I was home that day.</p><p>A second Cowboy ordered one day later did not have this problem.<br>So I’m sure this is an exception which is the fault of the delivery company.</p><p>Both the box and the goods were undamaged, which is the most important.<br>I didn’t detect any scuffs on the aluminium on initial inspection.👌</p><p>Installing the Cowboy is easy and all tools needed are provided in the box.</p><ul><li>You have to straighten the wheel and handlebars</li><li>Set the stem height of the saddle</li><li>Screw in the paddles</li><li>Charge the battery (it had about 30% battery when received)</li><li>Download the app and scan the QR code</li></ul><p>Whilst adjusting the stem of the saddle it already scratched the aluminium on the back of the saddle stem. 😢</p><p>There is also an accessories box included it comes with:</p><ul><li>An extra front light (rechargeable battery)</li><li>An extra red light to attach to a rug sack for example (rechargeable battery)</li><li>A bell</li><li>Wheel Reflectors (orange)</li><li>Back Reflector (red)</li><li>A USB (type A) for charging the extra lights.</li></ul><p>I only attached the bell and left the other accessories in the box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KUEH7mxx341mor2sUuIIAA.jpeg" /><figcaption>Standard handlebar position on the left, right Cowboy has a upright stem attached</figcaption></figure><h3>Ride</h3><p>Whilst my initial impressions during the test drive where wonderful, driving the bike for longer journeys showed the true nature of the Cowboy.<br>It lacks any springs or dampening which results in a very hard drive.<br>Every pothole in the road is magnified and jolts though your whole body.</p><p>Like previously mentioned the Cowboy has set its eyes on sportiness which was one of the main reasons I was considering the VanMoof more initially.</p><p>To make matters even worse the saddle is a hard as a plank and the handlebar can’t be moved upward. Meaning your only seating position is fixed at a 60° angle with your hands pushing hard on the handlebars.<br>After a while your hands get sour and a constant pain is felt in your hands and butt.</p><p>In order to fix this I ordered a whole arsenal of different bike parts to make the Cowboy more comfortable. See the accessories section.</p><h4>Motor</h4><p>Something that did live up to the expectations was the motor!<br>I provides ample power from the get go and is at its best on flat surfaces.</p><p>It is silent and can’t be heard whilst driving.</p><p>In uphill situations you wish the bike gave you that extra push, combined with the single gear ratio you can even struggle to get uphill. Something I didn’t really expect from an e-bike.</p><h4>Single Gear</h4><p>The bike is limited by its single gear, if you want to go any faster you will have to peddle like a lunatic and the motor shuts off above 25km/h.<br>It is therefor hard/tiring to go any faster than 30km/h and you simply stop peddling if the peddles are going faster than your legs can follow.</p><p>Especially when there is no wind the single gear is holding the <em>sporty</em> e-bike back. In a future Cowboy it would make sense to be able to have variable gears.</p><h3>Battery</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-gVaFtag47CTqgYKLt2UaA.gif" /><figcaption>A nice attention to detail; when taking out the battery like on the GIF ☝️ the frame is protected by some rubber preventing you from damaging the paint on the aluminium.</figcaption></figure><p>The battery is removable by inserting a key and can be charged separately. 👌</p><h4>Charging</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oUia1JSm_LdSpdTPtHrPrg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D33NKgN71tTHSbleOGjVRg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5HnMZg3E6-EoqGldR49MYQ.jpeg" /><figcaption>Hefty 252W battery</figcaption></figure><p>According to the Cowboy site the battery is charged from 0–100% in 3.5 hours. In reality I didn’t really care.<br>Whenever the battery would almost be empty I would take it inside and charge it and only take it out the next bike ride.</p><p>Range anxiety is a thing, but even with only 1 LED remaining it will still give you 14km of range which should cover most situations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VkRolotYHJZeA6SVeQJ6qg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wq-6Mm-q6VHuwRinS_hQbw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wx58hUnsmysYrOiyiGcArw.jpeg" /></figure><p>Whenever the battery is charging the charger indicates this with a red LED light, a green LED means the battery is fully charged.</p><h4>Red Light</h4><p>The back red light is integrated in the battery.<br>Whilst clever it’s also a weak point.</p><p>There is no obvious way to replace the light if it would deplete or if it would break. Leaving you with no option to replace the whole battery, which is probably the most expensive part of the whole bike.</p><p>If you make an emergency stop the back lights flashes rapidly like on a car.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fhqqz-K_BxYs%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dhqqz-K_BxYs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fhqqz-K_BxYs%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/650b9e0514b37e124763dba27b4bf8ca/href">https://medium.com/media/650b9e0514b37e124763dba27b4bf8ca/href</a></iframe><h4>Range</h4><p>The acclaimed 70km of range seems to be spot on.</p><p>The range can easily be checked in the app or via the LEDs on the frame.</p><p>Only further ownerships and use will prove the degradability of the battery.</p><h3>Accessories</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vS-GvOJkZmFEPti7UAMEyA.png" /><figcaption>Modifications done to my Cowboy</figcaption></figure><p>The Cowboy by standard is poorly equipped and has a very hard ride.<br>In order to make it more comfortable I changed multiple key parts of the bike to personal preference.</p><p>Cowboy has an an approved <a href="https://cowboy.tools/">accessories site</a> available, but it lacks explanation, options and (installation) reviews.<br>Leaving it to you to figure it out yourself. Definitely something they can improve upon since they could even make their own custom ones and earn more money that way.</p><h4>Handlebar stem adjuster/extender</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NMZn4wzz4b3YEK-39Qr0iA.jpeg" /></figure><p>This is a must have.<br>It allows you to pivot the handlebar in a more upright position allowing your back to relax and sit in a more upright position.</p><h4>Saddle</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7HC8UJRF0Cw7fXoS1T_NdA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A6JEJjuQiDTJBxn03UM1GA.jpeg" /><figcaption>Left original — Right Ergon Saddle</figcaption></figure><p>Don’t use the default one your butt will thank you.<br>As you can see it is very shallow and does not provide any support.</p><h4>Stand</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_gX6VAacUr-tijKKbd5bmg.jpeg" /></figure><p>By default there is no stand at all.<br>I picked the recommended BTWIN 500 one from the Cowboy site.<br>I had some trouble installing it since it mounts at a sensitive point on the bike, next to where the electrical wires run. It also detached a few times, but now it has been fixed in place and been reliable ever since.</p><h4>Lock</h4><p>Be aware that due to the thick(er) tires it is oftentimes difficult to find a spot to leave your bike.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z93xU9uQ2kF84nMnGPuCnw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ApzR3jRq62sDDLcpwRQ7CA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EeBXCK45CJCW-6d6pP6aIg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MiNgm_qWOEOufckNbfXUtQ.jpeg" /><figcaption>Finding creative ways to leave your bike safe.</figcaption></figure><h4>Honourable mentions</h4><p>Some other accessories equipped on the other Cowboy3 include:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sOnCvASS504wkEjaAk5qCQ.png" /></figure><h3>Cowboy App</h3><p>The app is literally key to the bike and is often very underexposed in other reviews.</p><p>The app is available for both <a href="https://play.google.com/store/apps/details?id=bike.cowboy.app">Android</a> and <a href="https://apps.apple.com/be/app/cowboy-electric-bikes/id1262900539">iOS</a> users.<br>It offers a very clean look and is very responsive.<br>The following will explain my experience with version 2.9.2 on a OnePlus 6 and OnePlus 8 Pro both running Android 10.</p><p>Keep in mind the app is the only way to unlock the bike, if your phones dies the motor will not start! You can if you really want still drive it without assistance.</p><h4>Bluetooth</h4><p>The app connects with the bike over Bluetooth.</p><p>Upon opening the app a lock appears that you long press to unlock/lock.<br>That is <strong>IF</strong> the phone detects the bike. Most of the time it does <strong>NOT</strong> detect it.<br>This was <em>slightly</em> frustrating. Waiting did not help…</p><p>The best way to get it to finally work was to disable Bluetooth and re-open the app. Now it has become a habit of turning on and off my Bluetooth before starting a bike ride. The future is here kids.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*KIuQ7Hh9IXy-FIrtaT-4sw.gif" /><figcaption>locking and unlocking the bike</figcaption></figure><p>There is a better way to unlock the bike with <em>Auto unlock, </em>which for some reason is turned off by default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HMxE4wQW97cORMMF-EqWiw.png" /><figcaption>You can find the option in the menu under My Bike &gt; Auto Unlock</figcaption></figure><p><em>Auto unlock </em>will detect if you get nearby your bike, the bike’s battery indicator LEDs will start pulsating letting you know it detects your presence.<br>Upon moving the bike it will automatically unlock the bike.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F90FsRSEnINg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D90FsRSEnINg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F90FsRSEnINg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d604c97ce33f93730b23b8bddfe31823/href">https://medium.com/media/d604c97ce33f93730b23b8bddfe31823/href</a></iframe><p>Once you enable the feature a persistent notification will appear from where you can always check the latest battery level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*EYjHo8RbPMJ0cgB47knXZg.jpeg" /></figure><p>For a feature request it would be nice if it would be possible to unlock the bike by using NFC instead and use Bluetooth as a fallback.<br>Something you also see in the car industry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*3BSx9jHIPV-NqNxO8clreg.gif" /></figure><h4>Day and Night Theme</h4><p>The app comes in both a light and dark theme and will automatically switch depending on the time of day.<br>A nice and welcoming addition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L-Xe0FGvxz5EvknTQtGjqg.png" /></figure><h4>Battery Life</h4><p>The <strong>biggest</strong> downside from the app is the battery consumption when driving.<br>I don’t have a phone mount attached to my bike so I leave my phone in my pocket while biking. <br>Nonetheless the app consumes <strong>way too much power</strong>.<br>Following screenshots were taken after a 23km drive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iIkEaWgIKjjIVxUlc8mPTw.png" /><figcaption>OnePlus 6 32% — OnePlus 8 Pro 14%</figcaption></figure><p>I first thought this was because the bike was feeding GPS coordinates to the app. However I tried turning off my Bluetooth as soon as I turned on the bike and I still received a trip history after stopping.<br>However my phone battery was did not deplete so easily as with the Bluetooth on.</p><p>Maybe someone from Cowboy could make a statement on this?</p><h4>Trip History</h4><p>Every trip you take automatically gets recorded in the app.<br>Sometimes the trip will only show up once the bike has been locked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kg-wtTKGs0g3f45naxYLuA.png" /><figcaption>Trip History and the navigation</figcaption></figure><p>Next to the trip history a turn by turn navigation is available in the app which uses Google Maps.<br>Of course you would need a phone mount to effectively use it which does not come as standard.</p><h4>Easy Rider</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WDWL_x32_MBdpZq7lmf-IA.png" /><figcaption>Basic — Standard — Plus Plan</figcaption></figure><p>Like mentioned before Cowboy offers an Easy Rider insurance.<br>As standard you can locate your bike by using the GPS function.</p><h4>Safety</h4><p>When the bike detects you are involved in an accident it will notify a preconfigured contact.<br>That person will see your current location and respond appropriately.<br>I have not tested this, but you can see it working in this Youtube <a href="https://youtu.be/OiG0D8b6CIM">video</a> (Dutch)</p><h4>Theft Warning</h4><p>In the <strong>Standard Plan </strong>you’ll be notified as soon as the bike gets stolen.<br>I tested the theft warning by stealing my own bike.</p><p>As soon as you start driving a locked bike the battery LEDs, front and back lights will start flashing rapidly.<br>I don’t believe this will hold back a thief. It would have been better if an audible alarm was implemented like on the VanMoof.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F3ny0tPIokBg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D3ny0tPIokBg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ceafb0cabed9354a207fd3aeec0d1477/href">https://medium.com/media/ceafb0cabed9354a207fd3aeec0d1477/href</a></iframe><p>In the meanwhile on the phone of the owner you will receive a notification telling your bike is being moved.<br>You can immediately take action by tracking your bike by GPS.<br>Every few seconds a newly updated live position is sent to your phone so you can track where it currently is.<br>Of course you should always go to the police first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NobJ7lmsM0SIk8TWmGJu4g.png" /></figure><h4>Updates</h4><p>Sometimes a firmware update is available for your bike.<br>The update procedure requires you to connect to the bike over Bluetooth and wait until the updates completes.</p><p>Who would ever thought you would need to update your bike? 😅</p><p>The updates procedure takes a minute or two.<br>If the update fails it can easily be restarted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cq8QkpfFXGhUpI6TeaxMXA.png" /></figure><h3>Verdict</h3><p>Before deciding if you want a Cowboy I highly recommend testing one first.<br>The initial push in the back will give you a kick, but keep your eyes out for comfort too.</p><p>The slogan for this bike ‘<em>Electric bike for the urban drivers</em>’ doesn’t really fit.<br>It seems like the Cowboy has an identity crisis. It tries to be both sporty and a city bike. Except it does neither perfect. <br>The motor cuts power above 25km/h and with a single gear you will have a hard time exceeded 30km/h comfortably.<br>It’s also no city bike, therefore the ride is way too hard and the seating position suboptimal to be called a city bike.</p><p>As standard the Cowboy is also too bare bones for the price, therefore be prepared to spend some more on bike accessories. It is a lost opportunity from Cowboy to invest more in to this.</p><p>The app also has its fair share of quirks, but this can be improved with future software updates. eg. Bluetooth stability, power consumption, …</p><p>However I’m still very happy to own this bike.<br>Riding on it now with all the mods is fun.<br>Only time will tell how this bike will age.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a57decaf991f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Porting the Flemish news app to Flutter]]></title>
            <link>https://medium.com/vrt-digital-studio/porting-the-flemish-news-app-to-flutter-50620453b346?source=rss-a95d50081208------2</link>
            <guid isPermaLink="false">https://medium.com/p/50620453b346</guid>
            <dc:creator><![CDATA[Tim Rijckaert]]></dc:creator>
            <pubDate>Mon, 13 Jan 2020 15:14:20 GMT</pubDate>
            <atom:updated>2020-01-14T09:44:01.714Z</atom:updated>
            <content:encoded><![CDATA[<h4>A retrospective overview of how we recreated the VRT NWS app in Flutter.</h4><p>VRT NWS is part of Belgium’s national media VRT. <br>The VRT NWS brand serves as their news app. On a daily basis it serves 350,000 active users.<br>Which means it is in the top 10 news apps in Belgium.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*McnYhd2WApgiA9hkAMjiOw.gif" /></figure><p>Analytics showed the future is in mobile and our stakeholders decided it was time to revamp the existing native app.</p><p>How did we end up deciding for Flutter 💙 and how did we experience the switch? With this blogpost we hope you pick the right tool for the job.</p><p><strong>tl;dr </strong>Download our public beta for either <a href="https://play.google.com/apps/testing/be.vrt.mobile.android.deredactie">Android</a> or <a href="https://testflight.apple.com/join/JkoMA8Aa">iOS</a> and leave your feedback.</p><h3>Back in time</h3><p>How did we end up choosing Flutter, an emerging new cross platform technology, for our most important visible app?<br>In order to get the full picture we need to understand where we are coming from.</p><h4>Deredactie.be (2015 — 2017)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*J6dAn2-dHx31BeS2oojWYw.jpeg" /><figcaption>Deredactie app</figcaption></figure><p>In March 2015 we launched our first mobile news app.<br>At that point it had been in the making for over a year.</p><p>Prior to VRT NWS<em>, Deredactie</em> was the official brand name.</p><p>The app was very simple and straightforward. <br>An endless scrolling list served the latest headline articles. <br>You could read offline thanks to an internal database.</p><p>In the hamburger menu you could easily switch between categories or even rewatch your favourite VRT NWS tv shows.</p><p>Even though the app worked incredibly <strong>snappy</strong>, it also had some considerable downsides. The most important ones were:</p><ul><li>Editors worked in a website environment unknowing how things would look in the app. <br>Every website component needed to be ported to a native component.<br>This not only took <strong>way too much time</strong>, but often times did not look completely similar to the website.<br>Even worse: web embeds simply did <strong>not render in the app</strong>.<br>This was frustrating not only for the editor, but for the end user as well.</li><li>The endless scrolling list meant the app was <strong>hard to navigate</strong> to retrieve your relevant content.</li><li><em>Deredactie </em>app talked directly to the CMS at the time. <br>The <strong>CMS output was suboptimal for mobile use</strong>. This resulted in a lot of business logic in both iOS and Android to get the correct data.</li></ul><h4>VRT NWS Rebranding (2017 — 2019)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wIJGoMQsbUJVTIvQC9JlDQ.png" /><figcaption>Current production version of VRT NWS</figcaption></figure><p>In August 2017 we rebranded <em>deredactie</em> to VRT NWS.<br>2017 was an important year, not only did we rebrand, we switched to a <strong>new CMS</strong> (AEM), moved to the cloud (AWS) and overhauled our site and app.</p><p>The rebranding allowed us to start from a blank canvas and learn from our mistakes.<br>We again agreed for native development to ensure a responsive feel.</p><ul><li>However we opted for <em>WebViews</em> in our article details. This alleviated the problem of creating native component for equivalent web components. Thus cutting development costs.</li><li>A better navigation pattern; We split up our main app in to 3 sections.<br>Headlines — , most recent — and popular articles.<br>A bottom navigation gives you access to videos, audio (podcast) and ‘<em>discover’</em> which houses our in depth articles and explainers.</li><li><strong>AEM</strong> allowed for easier transformation of the output JSON.<br>We installed a small backend between our CMS and our app which transforms the <em>dirty </em>CMS JSON to <em>ready to use JSON</em> in the app. Minifying the need for data processing on the clients.<br>Internally this is known as the Backend for Frontend or<strong> BFF</strong>.</li></ul><p>Despite of catering to the concerns of the preceding <em>deredactie</em> app, we created new problems:</p><ul><li>Turns out<em> WebViews</em> are not loved by the end user:<br>“<em>The app is slow!! 1 star” “The app does not load! 1 star”<br></em>We improved the mobile web performance significantly during the first months of our release, but nothing beats instant, native article details.<br>These comments have stabilised, but it’s still an eyesore.</li><li>The switch to AEM meant our editors now had access to a <em>WYSIWYG</em> interface where you can drag and drop components on a canvas.<br>This works perfectly for our app detail screens (<em>WebView</em>), but not for our native screens (headlines, recent, popular).<br>The app decides its own layout by a complex set of rules, of what we initially thought was well thought out.<br><br>As more AEM components emerged, it was not future proof. Business wants more flexibility and configurability with one <strong>single source of truth: AEM</strong>.<br>To make matters worse as time passed by the Android and iOS implementation drifted apart.</li><li>Native is <strong>slow in development and costly</strong>. It became increasingly more difficult to justify building a feature for both Android and iOS.</li><li>Due to circumstances our iOS code base became increasingly more difficult to <strong>deliver features in time</strong>. This gave the impression app development was stalling.</li></ul><h4>Flutter VRT NWS (2020 — …)</h4><p>Fast forward to June 2019 and the editors now have a lot of web components to style the <a href="http://vrtnws.be/">site</a>.<br>The current production app however only features about 2–3 different types with minimal difference.<br>Needless to say a lot of UI structure gets lost.</p><p>We knew we were put up for a challenge and were tasked to come up with a solution to following problems:</p><ul><li>When the editor designs the home page the app should look similar to the site structure.</li><li>The editors maintain one homepage for the site. The app should adapt accordingly.</li><li>Our single source of truth should be AEM.</li></ul><p>In order for our frontend to be more flexible we decided our <strong>BFF </strong>was now required to forward the UI structure from AEM to the app.<br>Besides the obvious data payload the BFF is now also responsible for sending text size, which font to use, colors and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6v8Ucq68MF9Pijk4ezPTlw.gif" /><figcaption>A small set of web components mapped to their respective Flutter components</figcaption></figure><p>Together with our designer, product owner, team and business we identified a set of components for the app</p><p>Effectively this meant our entire current JSON structure would drastically change. Furthermore our entire current data retrieval and view logic was now obsolete.</p><blockquote>In the end this meant we were to rewrite the app once again.</blockquote><h3>Enter Flutter</h3><p>It became more evident the next phase for this app was going cross platform.<br>As a team we played with different cross platform technologies before and always came back disappointed.<br>However Flutter felt, … different.</p><p>It proved to be a very potent candidate for our use case.</p><p>Our app has <strong>minimal use of true native features</strong>:</p><ul><li>Push notifications with <a href="https://medium.com/vrt-digital-studio/android-vrtnws-rich-push-2970975b406e">custom notification rich push</a></li><li>Background work; We periodically fetch the latest articles in the background.</li><li>Today Widget (iOS only)</li><li>Custom Video Library</li><li>Analytics</li></ul><p>To make matters even better there are <strong>no notable visual differences</strong> between our <strong>Android</strong> and <strong>iOS</strong> app.</p><h4>Proof Of Concept Time</h4><p>We wrote down a few potential bottlenecks to try and see how Flutter handles them before deciding. In particular we were really interested in the handling of <em>WebView</em> embedded within Flutter and <a href="https://medium.com/vrt-digital-studio/how-vrt-puts-accessibility-first-f96eff2fba5f">Accessibility</a>.</p><p>Not only that but how difficult was it to bridge the native feature listed above inside of Flutter?</p><p>We were pleased to see Flutter had support for both native views and accessibility.</p><p>Bridging required a bit more manual effort to implement. Since Flutter is quite a new platform popular libraries like Adobe Analytics did not have a Flutter counterpart.<br>Together with our custom libraries for our video player and other in-house analytics we quickly made a few reusable Flutter packages.</p><p>We even open sourced <a href="https://pub.dev/publishers/vrt.be/packages">a few libraries</a> and became a <a href="https://dart.dev/tools/pub/verified-publishers">verified publisher</a>.</p><h4>Dart</h4><p>Dart was a bit of a mixed bag for us.<br>Coming from Kotlin and Swift it felt like a step back in terms of language features. <br>However Dart is so similar to Java the switch was easy enough to be fully proficient within a week. The addition of the <strong>async/await</strong> is indispensable.<br>Another big plus is the great tooling support in IntelliJ!</p><p>We are convinced Dart is THE language that makes Flutter work like it does.<br>Without Dart no Hot Reload would be possible and there is no way adding that extra semicolon at the end of a line is that much of a burden.</p><p>Google knows Dart has to catch up and are making efforts. For example in Dart 2.3 they added the <strong>spread</strong> operator, support for <strong>if</strong>’s and <strong>for</strong>s in collections and not to mention the recently introduced <strong>extension</strong> <strong>support </strong>and the upcoming <strong>nullability support</strong>.</p><p><strong>Overall:</strong></p><p>No blogpost about Flutter is complete without mentioning Hot Reload. Coming from native development where waiting 2 minutes for a minimal change was commonplace, Hot Reload really stole everyone’s heart ❣<br>There is something about changing a value hitting save and immediately seeing that change happen on screen which sparks joy in every app developer.</p><p>The framework itself compared to native felt a lot less bulky. Not carrying so much cognitive load.<br>Creating a list of items is effortless in Flutter (like it should be), compared to on native side were you would first need to know all about recycling, adapters, views, lifecycles, item separators, item animators, … and then I intentionally forgot about Fragment and/or Activities.</p><p>The fact that everything is a Widget threw us off a couple of times, but we completely embraced this new paradigm.<br>It’s no secret Google turned to React Native for this idea, but Google perfected this by the vast set of built in Widgets which are dead easy to customise to business liking. This helped us to move quickly and create working mockups to show to business.<br>The tone was set; App development did not need to be slow nor expensive in the meantime we have already started to rework other VRT apps to make use of Flutter.</p><h3>Beta</h3><p>As a bonus we want to invite anyone interested in testing the bèta version of the VRT NWS Flutter app</p><p>Android:</p><p><a href="https://play.google.com/apps/testing/be.vrt.mobile.android.deredactie">Sign in - Google Accounts</a></p><p>iOS:</p><p><a href="https://testflight.apple.com/join/JkoMA8Aa">Join the VRT NWS beta</a></p><p>Thanks for reading.</p><h3>We are hiring!</h3><p>Check out the job description:</p><p><a href="https://jobs.vrt.be/nl/job/flutter-ontwikkelaar-vrt-nws-freelance-151243">https://jobs.vrt.be/nl/job/flutter-ontwikkelaar-vrt-nws-freelance-151243</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50620453b346" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vrt-digital-studio/porting-the-flemish-news-app-to-flutter-50620453b346">Porting the Flemish news app to Flutter</a> was originally published in <a href="https://medium.com/vrt-digital-studio">VRT Digital Products</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to run Flutter in the background]]></title>
            <link>https://medium.com/vrt-digital-studio/flutter-workmanager-81e0cfbd6f6e?source=rss-a95d50081208------2</link>
            <guid isPermaLink="false">https://medium.com/p/81e0cfbd6f6e</guid>
            <category><![CDATA[native]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[workmanager]]></category>
            <dc:creator><![CDATA[Tim Rijckaert]]></dc:creator>
            <pubDate>Thu, 01 Aug 2019 14:06:49 GMT</pubDate>
            <atom:updated>2019-08-02T08:17:34.443Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to run Flutter in the background?</h3><h4>Do you want to know how you can run Dart code — even when your app is not in the foreground?</h4><p>We are in the process of porting the <a href="https://www.vrt.be/vrtnws/nl/2018/09/17/mis-niets-van-de-gemeenteraadsverkiezingen-op-vrtnws-be/">VRT NWS app</a> to Flutter. <br>Our app consists of multiple news feeds with various contents:</p><ul><li>Headlines</li><li>Recent news</li><li>Popular news</li></ul><p>When a user opens the app, the user quickly wants to get the latest news.<br>Besides performing a network call when the feed becomes visible, we also setup a <strong>background job</strong> which periodically fetches the latest articles.<br>This is a setting that is exposed to the user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p34prygvMuGuKW5aNxWkfA.jpeg" /><figcaption>The Settings section about background fetching</figcaption></figure><p>However, in the new Flutter app it is <strong>Dart</strong>’s responsibility to perform network calls and parse the fetched data.</p><p>So we had to find answers to the following questions:</p><ul><li>How to schedule a background job in Dart?</li><li>How to run a Dart function in the background?</li><li>How to run a Dart function without an initialised Flutter engine ?</li></ul><p>There is an <a href="https://medium.com/flutter/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124">official blogpost</a>, but it goes in way too much detail about geofencing instead of talking about the Dart/Flutter part.</p><blockquote>TL;DR: We made a <a href="https://github.com/timrijckaert/flutter_workmanager">workmanager</a> package to facilitate the boilerplate of setting this up. It is still in alpha stage as we are currently testing it ourselves.<br>You can find it on <a href="https://pub.dev/packages/workmanager">pub.dev</a>.</blockquote><p>In this section, we’ll highlight the most important information about background execution on Flutter.</p><p>For more information about how the Flutter <a href="https://pub.dev/packages/workmanager">WorkManager</a> package works internally, please keep reading.</p><p>If you just want to get started with the package you can scroll to the bottom of the page.</p><h3>How to schedule a background job in Dart?</h3><p>Let’s first take a look at how we would do this without Flutter. <br>Android and iOS have very different approaches:</p><p>On Android, there are multiple ways to schedule a <strong>background job</strong>. It seems like every year there is a new and better way :</p><ul><li>AlarmManager</li><li>JobService</li><li>Firebase Job Dispatcher</li><li>and the latest one, <strong>WorkManager</strong>.</li></ul><p>The consensus these days seems to be on <a href="https://developer.android.com/topic/libraries/architecture/workmanager">WorkManager</a>. <br>Long story short: <strong>WorkManager</strong> provides an easy-to-use API where you can define:</p><ul><li>If a background job should run <strong>once</strong>, or <strong>periodically</strong></li><li>Apply multiple <strong>constraints</strong> like for example if a task needs internet connection, or if the battery should be fully charged, and so much more.</li><li>An <strong>interval</strong> of how many times a job should run.</li></ul><p>The job is guaranteed to run <em>some time </em>in the future.<br>Android takes full ownership of when is the best time to run background jobs, and batches these jobs (our app’s and others’) together for minimum battery drain.</p><p>If you want to learn more about WorkManager, have a look the <a href="https://developer.android.com/topic/libraries/architecture/workmanager">excellent documentation</a>.</p><h3>iOS</h3><p>On iOS, options are much more limited. The systems decides when to give an app the chance to perform a background fetch, so that the app appears to remain “alive”.</p><p>The only control we have is the <strong>minimum background fetch interval</strong>, but iOS may decide to never start our app to perform a background fetch (for example if we take too long before returning a UIBackgroundFetchResult to the completionHandler).</p><h3>Starting Flutter Engine in the background</h3><p>When a background job is started by native the Flutter engine is not active. So we are unable to run Dart.</p><p>Can Android/iOS starts the Flutter engine in the background?</p><p>Yes! We’ll first need to register a <strong>Dart</strong> <em>callback function</em> which will only be invoked whenever a background job is started by the native code.</p><p>This callback function is referred to as a <strong>callbackDispatcher.</strong></p><p>The process is the following on <strong>Dart</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6123a79df9bc8448e5515d5d277a69bb/href">https://medium.com/media/6123a79df9bc8448e5515d5d277a69bb/href</a></iframe><blockquote>📝 Note: The callbackDispatcher must be a top level function or a static function.</blockquote><p>The PluginUtilities#getCallbackHandle is probably something new.<br>This is the function responsible for taking your <strong>callbackDispatcher</strong> and <strong>registering</strong> it with the Flutter engine. <br>It can be seen as a simple <strong>key-value map</strong> inside the Flutter engine.</p><p>The <strong>key</strong> is the <em>hashcode </em>of the <strong>callbackDispatcher.</strong> <br>The <strong>value</strong> is a <em>handle</em> to the entry point itself.</p><p>We only send this <em>hashcode </em>to native over a MethodChannel. <br>Android/iOS will then save it for later use.</p><blockquote>⚠️ Careful: Renaming or moving an entry point to a different file in between registrations may cause the map to be out of sync.</blockquote><p>Once a job is actually triggered in the background on either iOS or Android we need to do the opposite.</p><p>We need to retrieve the <em>hashcode</em> and lookup its associated <strong>callbackDispatcher </strong>function.<br>Flutter provides some convenience methods to start a Dart process from arguments.</p><p>For example on Android it looks something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22abefa88a4755fe783226c05eb39fca/href">https://medium.com/media/22abefa88a4755fe783226c05eb39fca/href</a></iframe><h3>Flutter WorkManager Plugin</h3><p>To make our life (and yours 😉) easier, we developed a Flutter plugin which already handles all the above mentioned boilerplate code.<br>It makes use of the WorkManager API’s on Android and performFetch on iOS.</p><blockquote>📝 Note: that this plugin will work on both iOS and Android if you follow the setup steps first found in the <a href="https://github.com/vrtdev/flutter_workmanager/blob/master/README.md#platform-setup">README</a>. The following example assumes you have.</blockquote><p>Like we explained the plugin takes care for you to register the <strong>callbackDispatcher</strong>. Just call WorkManager.initialize(<strong>callbackDispatcher</strong>)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e18ae2c7c8c1293ddcf36b70613e92f9/href">https://medium.com/media/e18ae2c7c8c1293ddcf36b70613e92f9/href</a></iframe><p>With the help of the registerOneOffTask we tell Flutter explicitly to start an Android job. <br>The value of myTask variable will be returned to the registered <strong>callbackDispatcher</strong> so you can differentiate if you have multiple tasks.</p><p>iOS’ performFetch will always return a fixed value of Workmanager.iOSBackgroundTask .</p><p>This is the simplest of example, but more options can be configured on Android. Take a look at the <a href="https://github.com/vrtdev/flutter_workmanager/blob/master/README.md#customisation-android-only">README</a></p><p>Special shoutout to Jérémie Vincke for implementing the iOS part of the plugin and for co-writing this Medium post.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81e0cfbd6f6e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vrt-digital-studio/flutter-workmanager-81e0cfbd6f6e">How to run Flutter in the background</a> was originally published in <a href="https://medium.com/vrt-digital-studio">VRT Digital Products</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[VRT NWS Android Rich Push]]></title>
            <link>https://medium.com/vrt-digital-studio/android-vrtnws-rich-push-2970975b406e?source=rss-a95d50081208------2</link>
            <guid isPermaLink="false">https://medium.com/p/2970975b406e</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[custom-notification]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[native]]></category>
            <category><![CDATA[rich-push-notifications]]></category>
            <dc:creator><![CDATA[Tim Rijckaert]]></dc:creator>
            <pubDate>Thu, 11 Apr 2019 08:54:03 GMT</pubDate>
            <atom:updated>2019-04-19T12:19:31.840Z</atom:updated>
            <content:encoded><![CDATA[<h4>How we managed to make our notification stand out from the crowd</h4><p>Our <a href="https://play.google.com/store/apps/details?id=be.vrt.mobile.android.deredactie">VRT NWS</a> app is in big competition with other news apps to grab your daily need for news. One effective approach to lure users is by using push notifications.<br>Every time a push is sent we see a huge influx on our dashboards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*EAOIfITz9xT2ZfrXDREMbg.png" /></figure><p>Besides the content, the way a push notification is presented to the users can be a deciding factor. <br>Standing out is key!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hyif4waF1hNU8AH4xnq4MQ.png" /><figcaption>VRT NWS’ Custom Notification</figcaption></figure><p>Our custom notification features a full width image and allows for better branding (look at that big VRT NWS logo!). <br>Whilst still adhering to the look and feel of the Android ecosystem.</p><p>This post will be about how we went from a <em>boring </em>push notifications to a <em>rich push notifications.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y2NaFzmgtgQ16A-Bx87qpA.png" /></figure><h3>Incremental Steps</h3><p>Android offers many ways of customizing your notification to your heart’s content.<br>Besides the obvious ways of choosing a custom notification icon or background color, Android also offers a <a href="https://developer.android.com/training/notify-user/expanded">few predefined view</a>s you can choose from:</p><ul><li>BigTextStyle</li><li>Messaging Style</li><li>BigPictureStyle</li><li>InboxStyle</li><li>MediaStyle (shown above)</li></ul><p>One such view we investigated was with the use of a <a href="https://developer.android.com/reference/android/app/Notification.BigPictureStyle">BigPictureStyle</a>.<br>It adds a placeholder where you can store an image.<br>However we did not like the way the text is cut off at the end and the placement of the featured image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*akP443gVdYTtGdQnIQQmhg.png" /></figure><p>Another option is to use the .setLargeIcon(Bitmap bitmap)on the NotificationBuilder this adds a smaller icon on the right side of the notification.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7d20f8d7a364b693e409721da96be76/href">https://medium.com/media/a7d20f8d7a364b693e409721da96be76/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kvt20w-bru39g4b5QUy5Kg.png" /></figure><p>Even though this might seems like a small change. Providing a small icon makes your notification stand out more than 99% of all the other notifications.<br>We opted to go live with this and let our user get accustomed to this little article photo.</p><p>But of course we did not stop there.<br>We drew inspiration from <a href="https://design.google/library/material-design-awards-2016/">Kitchen Stories</a>’ custom notification and wondered how they did it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*rJe0_vZ9jgZIwv8LG8il4g.png" /></figure><h3>Custom Notification Layouts</h3><p>Enter the realms of custom notification layouts.</p><h4>RemoteView</h4><p>A custom notification is done by setting a RemoteView on the NotificationBuilder<br>If you have ever created a widget this will be very familiar.<br>A RemoteView is limited to support for the following layouts:</p><ul><li><a href="https://developer.android.com/reference/android/widget/AdapterViewFlipper.html">AdapterViewFlipper</a></li><li><a href="https://developer.android.com/reference/android/widget/FrameLayout.html">FrameLayout</a></li><li><a href="https://developer.android.com/reference/android/widget/GridLayout.html">GridLayout</a></li><li><a href="https://developer.android.com/reference/android/widget/GridView.html">GridView</a></li><li><a href="https://developer.android.com/reference/android/widget/LinearLayout.html">LinearLayout</a></li><li><a href="https://developer.android.com/reference/android/widget/ListView.html">ListView</a></li><li><a href="https://developer.android.com/reference/android/widget/RelativeLayout.html">RelativeLayout</a></li><li><a href="https://developer.android.com/reference/android/widget/StackView.html">StackView</a></li><li><a href="https://developer.android.com/reference/android/widget/ViewFlipper.html">ViewFlipper</a></li><li><a href="https://developer.android.com/reference/android/widget/AnalogClock.html">AnalogClock</a></li><li><a href="https://developer.android.com/reference/android/widget/Button.html">Button</a></li><li><a href="https://developer.android.com/reference/android/widget/Chronometer.html">Chronometer</a></li><li><a href="https://developer.android.com/reference/android/widget/ImageButton.html">ImageButton</a></li><li><a href="https://developer.android.com/reference/android/widget/ImageView.html">ImageView</a></li><li><a href="https://developer.android.com/reference/android/widget/ProgressBar.html">ProgressBar</a></li><li><a href="https://developer.android.com/reference/android/widget/TextClock.html">TextClock</a></li><li><a href="https://developer.android.com/reference/android/widget/TextView.html">TextView</a></li></ul><p>This means:</p><ul><li>No support for interactive views. So no view manipulations inside a notification. Even though ViewPager is supported you can’t just swipe between pages inside a notification.</li><li>No custom font. Even though TextView is supported.</li><li>No support for <a href="https://developer.android.com/reference/android/support/constraint/ConstraintLayout">ConstraintLayout</a><br>However for a simple layout other ViewGroup‘s should be more than adequate.</li></ul><p>We started off by creating a custom layout in XML</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b74142116d602e53cdc56272d45a3bd3/href">https://medium.com/media/b74142116d602e53cdc56272d45a3bd3/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*2GcLoyNkaieyc5RR9za4pQ.png" /><figcaption>Layout Preview</figcaption></figure><p>As you can see from the <em>Layout Preview</em> we provided a <em>blackish</em> gradient on top of the image, so the top - (logo) and bottom part (text) are more readable and the background image is a bit more muted.</p><p>Android provides the .setBigContentView and .setContentView methods.<br>Both take a RemoteView as an argument.</p><blockquote>According to <a href="https://developer.android.com/training/notify-user/custom-notification">the official documentation</a> a <em>big content view</em> can be up to 256dp maximum height and a <em>small content view</em> 64dp.</blockquote><p>As the names suggest you can differentiate how your notification looks if the notification is expanded or not.<br>We simply opted for a normal text notification instead of providing an alternative small custom layout.</p><h4>ConstraintLayout in RemoteView</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yyX2T4w3x5CFi7J6SVDpzg.png" /></figure><p>Note that our notification_pill is a ‘<em>complex’</em> custom view which makes extensive use of ConstraintLayout and custom drawables.<br>The custom view is used throughout the app and simply refactoring it to use the supported ViewGroup`s was no option. So we came up with an elegant solution to this problem.</p><p>We solved this by drawing a Bitmap of this image when creating the RemoteView.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cfdd0d8a0fb4bfb9263b45677d7b0e4/href">https://medium.com/media/3cfdd0d8a0fb4bfb9263b45677d7b0e4/href</a></iframe><p>Using this Bitmap and the Bitmap of the article, inflating and binding to this XML differs slightly from how you would normally inflate a layout.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52778f800e84ae6e2bc6b8d3940972aa/href">https://medium.com/media/52778f800e84ae6e2bc6b8d3940972aa/href</a></iframe><p>After that it is as easy as setting this RemoteView on the builder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4f34a0e2b9718f205ec6514cd09e9e8/href">https://medium.com/media/e4f34a0e2b9718f205ec6514cd09e9e8/href</a></iframe><p>Et voilà</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a6RYumdQAR61zhyBWQUkMA.png" /></figure><p>Some lessons learned:</p><ul><li>Make sure to test your rich push notifications on different devices. There is a reason why Android opted to go for a standardized way of showing notifications. <br>We learned this the hard way and of course it involved a Samsung phone.<br>They have a custom dark mode which made our white text unreadable.</li><li>When a push is received we do a backend call to get the image url to start downloading the image. If this were to fail we do not want the user to not see any notification. That is why we opted to push a normal text notification first and simultaneously starting the image download. When ready we again post a notification on the same notification id.</li><li>Test on multiple devices to see if your custom notification is readable and usable.</li><li>You can bind multiple click listeners on RemoteViews. You can simply have two views leading to different views inside your app.</li><li>Make sure your backend/image service is able to cope with the high load received from a push.</li><li>Creating a custom notification is low hanging fruit. We had half a day of development on Android.</li><li>Business loves rich push notifications ♥️</li></ul><h3>BONUS! Live Election Results</h3><p>On the 26th of May 2019 the general elections will be held in Belgium. <br>As public broadcaster VRT has heavily invested in proper contextualization of these elections. A special page was therefore designed in the app with among other things: a voting guide, articles and explainer videos.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h1htLKaL7VSXBWz8Elo0VA.jpeg" /></figure><p>On the day of the elections we will automatically keep subscribers up to date with the latest results with a custom rich push notification.<br>The user doesn’t even have to open up the app.</p><p>The custom notification shows a little teaser image of the counted votes.<br>And as day goes by, the graph will expand full width indicating completion.</p><p>The payload of the push notification contains everything we need to construct this notification.<br>Yes, even that image. Encoded as Base64 inside the payload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*GfLOsMyaEhNtYTH-2MjUww.gif" /></figure><p>Thanks for reading this post.<br>Please feel free to clap, share or follow.</p><p>Questions? Leave them below and we will try and answer them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2970975b406e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vrt-digital-studio/android-vrtnws-rich-push-2970975b406e">VRT NWS Android Rich Push</a> was originally published in <a href="https://medium.com/vrt-digital-studio">VRT Digital Products</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How VRT puts accessibility first]]></title>
            <link>https://medium.com/vrt-digital-studio/how-vrt-puts-accessibility-first-f96eff2fba5f?source=rss-a95d50081208------2</link>
            <guid isPermaLink="false">https://medium.com/p/f96eff2fba5f</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[native]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[accessibility]]></category>
            <dc:creator><![CDATA[Tim Rijckaert]]></dc:creator>
            <pubDate>Wed, 08 Aug 2018 18:15:39 GMT</pubDate>
            <atom:updated>2018-08-09T19:42:06.976Z</atom:updated>
            <content:encoded><![CDATA[<p>At <a href="http://www.vrt.be/">VRT</a> we have always had a focus on accessibility.<br>So it came only natural to us to give the same treatment to our mobile applications. This devotion from our mobile team did not go unnoticed. <br>The accessibility-event held annually at the VRT consists of an external jury, judging new products.</p><p>In 2017 and again in 2018 we won the <a href="https://www.vrt.be/vrtnws/nl/2018/03/22/diversiteitsprijs/">accessibility trophy</a> for both the<a href="https://play.google.com/store/apps/details?id=be.vrt.mobile.android.sporza.voetbal"> Sporza Voetbal</a> — and the <a href="https://play.google.com/store/apps/details?id=be.vrt.mobile.android.deredactie">VRT NWS</a> app respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Br-MwSfshmExmZCGm2FGow.jpeg" /></figure><p>Historically accessibility users have always gravitated more toward iOS rather than Android since iOS at the time invested more into this field. <br>However, a shift has been going on in recent years from Google that shows Android is catching up. <br>The only thing needed to break this vicious circle is making Android developers aware and use the provided APIs. <br>In this technical blog post I will therefore share our experiences and tools we used when we made our apps more accessible.</p><h3>Developer vs OS</h3><p>A first distinction to make is what should be handled on an OS level and what should be implemented by you as a developer.</p><p>Out of the box Android enables settings for users with the most common disabilities. Think about the elderly, or people with bad eyesight in general having trouble noticing small text and icons on screen.<br>Also people with color blindness should ideally have one setting that applies color correction.<br>Android has got your back and exposes these user settings for not just your app but system-wide.</p><h4>Scale Text</h4><p>You can find the font increasing system setting under <strong>Settings &gt; Display &gt; Font Size</strong>. One caveat though is that developers still need to specify explicitly that a certain text can scale in font size. More about this later.</p><h4>Scaling the Whole UI</h4><p>Scaling only text might not be enough. Likewise, icons and other important visual widgets might be rendered too small.<br>So one other <em>(better?) </em>idea is to scale the whole UI.<br>This feature can be enabled under <strong>Settings &gt; Display &gt; Display Size</strong>.</p><p>However, this feature was only introduced in Android 7.0 (Nougat) so only more recent devices can benefit from this.</p><p>The upside to this is that there is 0% extra work that needs to be done by the developer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SpnrdOQk8LaNsdpL1GDPpw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*laoMaDfBb7Rns0CyGeJ08A.gif" /></figure><h4>Color Correction</h4><p>Another option Android provides is the color correction.<br>This allows color blind people to perceive the correct colors.<br>Android provides three most common color corrections:</p><ul><li>Deuteranomaly (red-green)</li><li>Protanomally (red-green)</li><li>Tritanomally (blue-yellow)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ln_Nq6YzzT4qzVExCqFJtQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*96N5rUQoN-GO-oPVc0IQ3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lsj01pzTWYx5zw-TpOa5gQ.png" /></figure><p>You can apply this color correction system wide. So there is no need for you as a developer to implement this feature in your app.</p><p>The setting is under<strong> Settings &gt; Accessibility &gt; Color Correction</strong></p><h3>Your accessibility user</h3><p>Just as there are different Android versions there are also a lot of different accessibility users:</p><ul><li>Physical disability</li><li>Intellectual disability</li><li>…</li></ul><p>Having one app to suit them all is <em>ambitious</em> therefore we took the physical disability as our main focus group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*Ben6XbDVgZNnYq5AqmV0bQ.png" /></figure><p>To understand what you should do to improve your app for this group it is crucial to understand how they interact with their Android smartphone.</p><h4>Blindness</h4><p>Visual impaired users navigate your app by using another app that makes use of the accessibility APIs.</p><p>Most notably or best known is the <a href="https://play.google.com/store/apps/details?id=com.google.android.marvin.talkback">Talkback</a> app from Google.<br>Talkback is factory installed on any Android device and is updated just like any other app regardless of Android version.<br>This ensures you will always get to enjoy the latest features.<br>Talkback is what they call a screen reader and audibly informs the user of anything that is going on at the screen.</p><p>The way Talkback works is by simply touching the display, Talkback will first vibrate to let you know your touch has been registered and then tell you what is currently being touched on the screen.<br>More advanced users will most likely benefit from using gestures to navigate around an app.<br>These custom gestures include navigating up, go to the next/previous item, opening the context menu or simply read everything on screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*tCm8lvdjp0y6N-ajw_2s0w.gif" /><figcaption>Gesture based Talkback</figcaption></figure><p>Therefore making sure all your views have the correct content description and have a logical layout is paramount.<br>A blind user should be able to have a visual map inside their head of were things are placed on screen. <br>This is yet another reason you can give your designer as to why you are better off sticking to the Material spec and maintain unity across the board. You wouldn’t want to confuse people having <strong>your</strong> hamburger icon in <strong>your</strong> app to be on the right instead of the usual left.</p><p><strong>Pro-tip:</strong> When in development you might want to enable the <em>Display Speech Output</em> this way you can see what is being said without annoying everyone else in the room trying to concentrate. You can find the setting under the <strong>Talkback settings &gt; Developer Settings &gt; Display speech output.<br></strong>Once enabled it will look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UOocyzZaEAvXR7rkHXTcKw.gif" /></figure><p><a href="https://play.google.com/store/apps/details?id=com.googlecode.eyesfree.brailleback">Brailleback</a> is another accessibility app. Again fully maintained by Google themselves and updates get distributed by the Google Play Store too.</p><p>It can run in conjunction with Talkback to provide either tactile feedback or both tactile and auditive simultaneously.</p><p>Instead of using Talkback the user can connect a small device that converts text into braille. It allows for full control over the device so it can also replace gestures to navigate the app.</p><p>I had the chance to witness a very proficient user on one of these devices and she could out type me any time.<br>These devices are quite an expensive purchase.</p><p><strong>Fun fact:</strong> They mostly keep their smartphone screen off, this helps them enormously with battery life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Z5Am-ubjeVSknwV0KBARA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-fdQr8VNrtFYIjDew6ZYgQ.jpeg" /></figure><p>Switch Access is sort of similar to Brailleback except for the Braille integration. Switch Access can be helpful for people with dexterity impairments that prevent them from interacting directly with the Android device. <br>Again a device is used to traverse through the different views on screen with the help of a connected <em>button.</em></p><p>Therefore it is again important to provide logical traversal order in your app. More about this later.</p><p>The switch devices are generally cheaper than the Brailleback enabled devices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*gtAfPpTB8A_WaREDAzMQFA.jpeg" /><figcaption>New Blue 2 Switch</figcaption></figure><h4>Tools for the developer</h4><p>When you design and develop an Android app there are multiple tools available that can aid you.</p><p>The <a href="https://play.google.com/store/apps/details?id=com.google.android.apps.accessibility.auditor">Accessibility Scanner App</a> can help you identify opportunities to improve your app for accessibility.<br>Simply download the app and load up an app you want to scan.</p><p>While scanning your screen it provides suggestions on which you can improve:</p><ul><li>Content labels</li><li>Touch target size</li><li>Clickable items</li><li>Text and image contrast</li></ul><p>As you can see from the screenshot we have some work to do on text contrast in the VRT NWS app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xDE8DiU9rD2vbKVJ06UfgA.jpeg" /><figcaption>Accessibility Scanner Report for VRT NWS</figcaption></figure><h4>Android Studio</h4><p>Yes, even Android Studio will warn you about different aspects to be wary of when developing an accessible app.</p><p>If you open up the theme editor you will see Android Studio warns you when there is insufficient contrast between certain colors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*5DhMzR24HtVqHr8kp8y2yw.png" /></figure><p>If you add an ImageView without a ContentDescription Android Studio will also warn you about this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*frXe8wVUOjQCGamoKciDlg.png" /></figure><p>Or when you define a text size which is likely to be barely readable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*ZGShLAInZLMAkeEoxtRecA.png" /></figure><p>Even better is to enable a Lint check for missing content descriptions and fail your build when a content description is missing.</p><pre># Add to your build.gradle<br>android {<br>    lintOptions {<br>        abortOnError true<br>        showAll true<br>        lintConfig file(&quot;vrtnws-lint.xml&quot;)<br>    }<br>}</pre><pre># Custom Lint file (vrtnws-lint.xml)</pre><pre>&lt;issue id=&quot;ContentDescription&quot; severity=&quot;error&quot;/&gt;</pre><pre># Run Checks</pre><pre>./gradlew lint</pre><p>When using the <a href="https://material.io/tools/color/">Color Tool</a> to compose your theme the tool dedicates a whole tab to accessibility.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5u6oT1QcijV7eKtFckRsKQ.png" /></figure><p>Even in the prelaunch reports on Google Play Console you get tips</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uykeKJpv-2Ga_6NZCeGp-w.png" /></figure><h3>VRT Sauce</h3><p>As you can already tell there are lots of great APIs and tools available for developers and the Android ecosystem is becoming increasingly more friendly for accessibility users.</p><p>What’s more is that when you stick to default implementations of the Android framework you will already have a minimum of accessibility features enabled in your app.</p><p>So what does VRT do extra on top to provide an even better experience?</p><p>I tried ordering them according to their importance.<br>With the tips on the bottom being the ones with lower priority.</p><h4>Content descriptions</h4><p>Make sure that every view that a user can touch has a correct label.<br>This will ensure that it gets picked up correctly by the screen reader.<br>If it is a static view you can do this in <strong>XML </strong>or programmatically.</p><pre># XML<br>&lt;TextView<br><strong>    android:contentDescription=&quot;@string/your_accessibility_text&quot;</strong><br>    android:layout_width=&quot;wrap_content&quot;<br>    android:layout_height=&quot;wrap_content&quot; /&gt;</pre><pre># Kotlin</pre><pre>val itemView: View = layout.find(R.id.someView)<br>itemView.<strong>contentDescription</strong><em> </em>= &quot;Your accessibility Text&quot;</pre><p>If a view is not of interest for an accessibility user, think of little icons, you can ignore the view by using:</p><pre>&lt;ImageView<br>    android:id=&quot;@+id/some_unimportant_icon&quot;<br>    android:layout_width=&quot;wrap_content&quot;<br>    android:layout_height=&quot;wrap_content&quot;<br>    android:importantForAccessibility=&quot;no&quot;/&gt;</pre><p>To alleviate the problem of generating a fitting accessibility text for both Android and iOS clients we fetch our accessibility text straight from our backend.</p><pre>[<br>  {<br>    &quot;id&quot;: &quot;1533565019306&quot;,<br>    &quot;title&quot;: &quot;Twee doden en tientallen gewonden&quot;,<br>    &quot;accessibilityText&quot;: &quot;Buitenland, Twee doden en tientallen gewonden bij de explosie van een tankwagen in Bologna, aangepast <strong>${time}</strong>, dit artikel bevat video&quot;<br>  }<br>]</pre><pre>    &quot;accessibilityText&quot;: &quot;Buitenland, Twee doden en tientallen gewonden bij de explosie van een tankwagen in Bologna, aangepast <strong>${time}</strong>, dit artikel bevat video&quot;<br>  }<br>]</pre><p>The only computing that needs to be done by the client is replacing the <strong>${time}</strong> with the correct time according to some business logic and place it on the <em>itemView</em>.</p><p>To make sure you don’t forget this we have a base layout interface which enforces you to have an accessibility text.<br>You could even make a default interface, but we rather wanted it to be explicit about it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da394162845f579021d3b89e2f98303b/href">https://medium.com/media/da394162845f579021d3b89e2f98303b/href</a></iframe><h4>Grouping of views</h4><p>When you are composing views together it makes sense to have but one content description for one block instead of each individual item.<br>The reason behind this is because screen readers like Talkback will otherwise read every little view separately. Grouping views together combines the accessibility text.</p><p>In the screenshot below we grouped all views in a list item as one accessibility group with a content description</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/228/1*4Zw-yi2Jnb0ZaR5wlnWN9A.gif" /></figure><p>The way Google recommends you to do this is by placing an android:focusable on to your parent ViewGroup however that breaks tab navigation as explained in this <a href="https://github.com/googlecodelabs/android-accessibility/issues/4">Github issue</a>.</p><p>We choose to place android:importantForAccessibility=&quot;no&quot; on each view that should be ignored by the screen reader and instead only provide a content description for the parent view.</p><p>This will also ensure that the gesture for going to the previous/next item (swipe left/right) is properly implemented</p><p>If you want more fine-grained control over what view should be selected next you can take a look at:</p><pre>android:nextFocusLeft=&quot;@id/view_selected_when_swipe_left&quot;    <br>android:nextFocusRight=&quot;@id/view_selected_when_swipe_right&quot;</pre><h4>Text Scaling</h4><p>In a previous section, we talked about how a user can enlarge text displayed on the screen. The only downside to this is that you should declare your font sizes in <strong>SP</strong> rather than in <strong>DP</strong>’s</p><pre>&lt;TextView<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:textSize=&quot;14sp&quot; /&gt;</pre><p>Even better would be to look at the <a href="https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview">auto sizing TextView</a> it allows for an automatically scaling TextView widget that will fill all available space.<br>Thanks to Jetpack it is backported all the way back to Android 14.</p><h4>State &amp; Correct Intent</h4><p>As a user is it important to know which page or which item is currently active.</p><p>Again by leveraging default views this behavior is done for you, but in situations where that is not the case, don’t forget to include it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Z6IlAr-qELhO6HEggx0cw.jpeg" /><figcaption>Default behavior of a TabLayout will tell you which tab is currently active</figcaption></figure><h4>Custom Views</h4><p>You might have custom views in your project fetching periodical results and showing new items in a colorful manner.</p><p>Consider notifying your visually impaired end user by using:</p><pre>view.announceForAccessibility(&quot;New items were being fetched&quot;)</pre><p>This will interrupt the screen reader and will broadcast the defined string.</p><p>Maybe your custom view is difficult to use or it has a dense set of buttons which would be annoying for people with dexterity impairments.<br>You could take a look at <em>AccessibilityDelegateCompat</em> this class allows you to define a custom view only for Accessibility users.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fcd84ba1e8aec85884bd865037b2ac5/href">https://medium.com/media/3fcd84ba1e8aec85884bd865037b2ac5/href</a></iframe><h4>Detect Accessibility On</h4><p>In some situation we are even changing the behavior of the app depending on when accessibility is enabled or not.<br>Think about running expensive beautiful animations.<br>Why would you want those if you can detect a user is using a screen reader.</p><p>We use a little utility class for this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30c49ac03fdbfc2d304b262350b58e61/href">https://medium.com/media/30c49ac03fdbfc2d304b262350b58e61/href</a></iframe><h3>Conclusion</h3><p>If you have come this far I hope that you were inspired to make your apps more accessible. As you can tell it is a rather low effort to fulfil and yet it means a lot to millions of users.</p><p>Got any questions? Leave them below.</p><p>Special thanks to <a href="https://www.digicreate.be/nl/diensten/28/websites?gclid=Cj0KCQjw1NzZBRCoARIsAIaMwuvQXnc0sdnnAj6y6QDxkH4rCkrFHOcoCklVWz_kkKJVjLwD6ojPZ3IaAnNsEALw_wcB">AnySurfer</a> and Marc Walraven.</p><h4>Follow @<a href="https://twitter.com/googleaccess">https://twitter.com/googleaccess</a></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q49-f4np7IM6GAKitSG-mw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f96eff2fba5f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vrt-digital-studio/how-vrt-puts-accessibility-first-f96eff2fba5f">How VRT puts accessibility first</a> was originally published in <a href="https://medium.com/vrt-digital-studio">VRT Digital Products</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FloatingMusicActionButton an AnimatedVectorDrawable implementation]]></title>
            <link>https://timrijckaert.medium.com/play-pause-stop-animated-vector-drawable-88a9df956d20?source=rss-a95d50081208------2</link>
            <guid isPermaLink="false">https://medium.com/p/88a9df956d20</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[vectordrawable]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Tim Rijckaert]]></dc:creator>
            <pubDate>Sun, 16 Oct 2016 18:18:12 GMT</pubDate>
            <atom:updated>2016-10-16T22:29:01.320Z</atom:updated>
            <content:encoded><![CDATA[<p>Every time I open the <a href="https://play.google.com/store/apps/details?id=au.com.shiftyjelly.pocketcasts&amp;hl=en">PocketCast</a> app I can’t help but repeatedly click on the play button to gaze at this wonderful animation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*dz-aTH7i4dt9TME2-QOxbg.gif" /><figcaption>I could watch this all day</figcaption></figure><p>Google even decided to place this particular animation in their <a href="https://material.google.com/motion/creative-customization.html#creative-customization-icons">Material Design Specs</a></p><blockquote>Transforming the play button to a pause button signifies that the two actions are linked, and that pressing one makes the other one visible.</blockquote><p>We thought it would be a good idea to implement this in our own radio player app.</p><p>The whole issue with making such animation is not that it’s difficult, however it requires a bit of tinkering around with different tools to get it right.<br>In this blog post I try and guide you through the steps I did to make this animation.</p><h3>Animated Vector Drawable</h3><p>Ever since API level 21 we got access to <a href="https://developer.android.com/reference/android/graphics/drawable/VectorDrawable.html">VectorDrawable</a> and <a href="https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html">AnimatedVectorDrawable</a>. Even better since the release of Android Support Library 23.2 we got support for older API’s.</p><p>An example of a simple <a href="https://developer.android.com/reference/android/graphics/drawable/VectorDrawable.html">VectorDrawable</a> can look like this</p><pre>&lt;vector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>        android:height=&quot;64dp&quot;<br>        android:width=&quot;64dp&quot;<br>        android:viewportHeight=&quot;600&quot;<br>        android:viewportWidth=&quot;600&quot; &gt;<br>    &lt;group<br>        android:name=&quot;rotationGroup&quot;<br>        android:pivotX=&quot;300.0&quot;<br>        android:pivotY=&quot;300.0&quot;<br>        android:rotation=&quot;45.0&quot; &gt;<br>        &lt;path<br>            android:name=&quot;v&quot;<br>            android:fillColor=&quot;#000000&quot;<br>            android:pathData=&quot;M300,70 l 0,-70 70,70 0,0 -70,70z&quot; /&gt;<br>    &lt;/group&gt;<br>&lt;/vector&gt;</pre><ul><li>The <strong><em>vector-</em></strong>tag defines the width and height of the vector as well as the viewportHeight and -Width.</li><li>The <strong><em>group-</em></strong>tag can help you to separate different parts of the vector.<br>You give it a name that later comes in handy when we start animating the vector.</li><li>The most important tag <strong><em>path</em></strong>-tag defines your actual shape with the pathData. The pathData defines clip path using the same format as “d” attribute in a SVG’s path data.</li></ul><blockquote>The most important thing when we want to morph different shapes into each other is that the paths should have exact same length of commands , and exact same length of parameters for each commands — <a href="https://medium.com/u/991272e72e68">Google Developers</a></blockquote><p>For example following paths are compatible for morphing</p><pre>&lt;string name=&quot;before&quot;&gt;M3,70 l 0,-70 70,70 0,0 -70,70z&lt;/string&gt;<br>&lt;string name=&quot;after&quot;&gt;M5, 50 l 0, -80 80, 80, 0, 10 -90, 50z&lt;/string&gt;</pre><p>The pathData includes coordinates on a 2D grid. Each letter represents a command that is used to draw. <a href="https://medium.com/u/fb6e00f3359c">Lewis McGeary</a> could not have explained it better than I can.</p><blockquote>Uppercase commands mean the coordinates given are absolute and lowercase means they are relative to wherever your ‘pen’ is currently at.</blockquote><blockquote>M3,70 : M is the moveto command and the numbers are coordinates, so this means move the ‘pen’ to position 3 on the x-axis and 70 on the y-axis, we’ll start drawing there.</blockquote><blockquote>l 0,-70 70,70 0,0 -70,70 : l is the lineto command, which draws straight lines, and the numbers are again coordinates. Note that this is a lowercase l therefore these coordinates are all relative.</blockquote><blockquote>Finally z which means closepath, it draws a straight line from where we are now, back to our starting point. — Lewis McGeary</blockquote><h3>Sketching on an old fashioned paper</h3><p>In order for our animation to work we started sketching the different points on a 128 by 128 canvas.<br>Drawing can help a lot here. Don’t be afraid of grabbing a piece of paper and a pencil to improve your spatial awareness.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yt7oEARDoID9iw0x57aV8A.png" /><figcaption>All the button states in their final state</figcaption></figure><h4>Play Button Coordinates</h4><p>You can see our <em>play</em>-button is composed out of 2 triangles. In order to be compatible for morphing to the <em>pause </em>and <em>stop</em>-buttons a fourth point has to be defined on the triangles. <br>The point is not visible because it’s placed at <em>(100,64)</em> so it overlaps with another point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nvI5I4Oupcuw5h1kO-LSlA.png" /><figcaption>play button upper part</figcaption></figure><p>We come up these four parts for the upper part</p><pre>(44, 32)<br>(44, 64)<br>(100,64)<br>(100,64)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*78Kr-K_FnbsZeDMu3lVpig.png" /><figcaption>play button bottom part</figcaption></figure><p>Only one extra coordinate <strong>(44, 96)</strong> for the bottom part is required</p><pre><strong>(44, 96)</strong><br>(44, 64)<br>(100,64)<br>(100,64)</pre><h4>Pause Button Coordinates</h4><p>In order to obtain the full effect from <em>play-</em> to <em>pause</em> state. We have to rotate the pause button -90°. Otherwise we get another effect then intended.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/205/1*7CbFsVAkD4vrPlbDzVm98Q.gif" /><figcaption>wrong</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/205/1*xGD1YWbNJIOb1dNdu39WGw.gif" /><figcaption>correct</figcaption></figure><p>During the morphing we will then rotate it back to its correct position</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1XXopNfu90hT1ho4D978Ew.png" /><figcaption>The pause button</figcaption></figure><p>We come up these four parts for the upper part</p><pre>(32, 40)<br>(32, 56)<br>(96, 56)<br>(96, 40)</pre><p>We leave a 16px margin between the two pause rectangles. <br>The results for the bottom part coordinates</p><pre>(32  88)<br>(32, 72)<br>(96, 72)<br>(96, 88)</pre><h4>Stop Button Coordinates</h4><p>For the stop button the same rules apply as with the <em>pause</em>-button so we rotate the object to -90°.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fpyh3lMZwi-NyDoD6Myyuw.png" /><figcaption>the stop button</figcaption></figure><p>The correct coordinates for the upper part</p><pre>(32, 32)<br>(32, 64)<br>(96, 64)<br>(96, 32)</pre><p>The bottom part</p><pre>(32, 96)<br>(32, 64)<br>(96, 64)<br>(96, 96)</pre><h3>Android Icon Animator</h3><p>A few weeks ago while browsing <a href="https://www.reddit.com/r/androiddev/">r/androiddev</a> I discovered <a href="https://romannurik.github.io/AndroidIconAnimator/">Android Icon Animator</a> by <a href="https://medium.com/u/90c74515fd18">Roman Nurik</a>. This marvelous tool allows you to just drag and drop any SVG and it will convert the SVG into the pathData.</p><p>Not only that but it allows you to see your animation before you even wrote one letter code. This let’s you wonder why Android Studio doesn’t come with tooling this easy. Sigh</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*eI2tu42L6OqQVa91vRPB3g.gif" /></figure><p>Any who, Create a simple triangle using your favorite vector creating tool (ex. <a href="http://www.adobe.com/Illustrator%E2%80%8E">Illustrator</a> or <a href="https://inkscape.org/en/">Inkscape</a>) and add one extra point.</p><p>Export the vector as SVG. Opening the SVG in any text editor will reveal it’s commands.<br>My command looked similar to this.</p><pre>M XX XX L XX XX L XX XX L XX XX Z</pre><h4>Play to Pause Animation</h4><p>Let’s use the <a href="https://romannurik.github.io/AndroidIconAnimator/">Android Icon Animator</a> tool to aid us in to making our first animation.</p><p>Replace the coordinates from the command above with the coordinates we found in previous step.<br>I recommend you to place this pathData in your strings.xml file to keep things tidy.</p><pre>&lt;!-- Play Icon --&gt;<br>&lt;string name=&quot;play_icon_upper_path_data&quot;&gt;M 44 32 L 44 64 L 100 64 L 100 64 Z&lt;/string&gt;<br>&lt;string name=&quot;play_icon_bottom_path_data&quot;&gt;M 44 96 L 44 64 L 100 64 L 100 64 Z&lt;/string&gt;</pre><pre>&lt;!-- Pause Icon --&gt;<br>&lt;string name=&quot;pause_icon_upper_path_data&quot;&gt;M 32 40 L 32 56  L 96 56 L 96 40 Z&lt;/string&gt;<br>&lt;string name=&quot;pause_icon_bottom_path_data&quot;&gt;M 32 88 L 32 72 L 96 72 L 96 88 Z&lt;/string&gt;</pre><p>Click on the icon and create a new group,<strong> </strong>name it: <strong>parts.</strong> In the parts-group create two more groups and name them: <strong>upperpart</strong> and <strong>bottompart.</strong></p><p>Your structure should now look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*q4Zz8pN6_MbUnL42fM7YFg.png" /></figure><p>In the <strong>upperpart</strong>-group create a path named <strong>upper.</strong><br>In the <strong>bottompart</strong>-group create a path named <strong>bottom.</strong></p><p>You should now see your vector appear on screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*yw9HV5xwKm8kJ7LBvSOgTw.png" /></figure><p>Click the <strong>New animation</strong> button. <br>Name your animation <strong>play_to_pause </strong>and leave the default duration at 300 ms.<br>Click the <strong>upper</strong> path and click on the little stopwatch logo, select <strong>pathData</strong>.<br>Change the <strong>toValue</strong> to the pause-pathData.</p><p>Repeat this step for the <strong>bottom</strong> path.</p><p>Your animation is almost done.<br>Click on the stopwatch icon for the parts group. Click on rotation and change the <strong>toValue</strong> to 90° degrees.</p><p>You can now use the slider to see the animation in action as it will render on Android.</p><p>Use the export function to generate your initial VectorDrawable and the chosen animations.</p><p>The export function is quite messy as it returns the animation in one XML file. <br>I extracted everything to the correct folders for maximum readability and re-usability.</p><p>Inside of the <em>drawable </em>folder paste the <em>play_icon.xml</em> which is our VectorDrawable</p><pre>&lt;vector<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:width=&quot;128dp&quot;<br>    android:height=&quot;128dp&quot;<br>    android:viewportWidth=&quot;128&quot;<br>    android:viewportHeight=&quot;128&quot;&gt;<br>    &lt;group<br>        android:name=&quot;@string/play_icon_group_parts&quot;<br>        android:pivotX=&quot;64&quot;<br>        android:pivotY=&quot;64&quot;<br>        android:scaleX=&quot;1&quot;<br>        android:scaleY=&quot;1&quot;&gt;<br><br>        &lt;group android:name=&quot;@string/play_icon_group_top&quot;&gt;<br>            &lt;path<br>                android:name=&quot;@string/play_icon_top_path_name&quot;<br>                android:pathData=&quot;@string/play_icon_upper_path_data&quot;<br>                android:fillColor=&quot;@android:color/black&quot;<br>                android:strokeLineCap=&quot;butt&quot;<br>                android:strokeLineJoin=&quot;miter&quot;<br>                android:strokeMiterLimit=&quot;10&quot;/&gt;<br>        &lt;/group&gt;<br>        &lt;group android:name=&quot;@string/play_icon_group_bottom&quot;&gt;<br>            &lt;path<br>                android:name=&quot;@string/play_icon_bottom_path_name&quot;<br>                android:pathData=&quot;@string/play_icon_bottom_path_data&quot;<br>                android:fillColor=&quot;@android:color/black&quot;<br>                android:strokeLineCap=&quot;butt&quot;<br>                android:strokeLineJoin=&quot;miter&quot;<br>                android:strokeMiterLimit=&quot;10&quot;/&gt;<br>        &lt;/group&gt;<br><br>    &lt;/group&gt;<br>&lt;/vector&gt;</pre><p>Make a <em>play_to_pause_animation.xml</em> which will be our actual AnimatedVectorDrawable</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;animated-vector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>                 android:drawable=&quot;@drawable/play_icon&quot;&gt;<br><br>    &lt;target<br>        android:name=&quot;@string/play_icon_group_parts&quot;<br>        android:animation=&quot;@animator/rotate_90_animation&quot;/&gt;<br><br>    &lt;target<br>        android:name=&quot;@string/play_icon_top_path_name&quot;<br>        android:animation=&quot;@animator/upper_play_to_pause_animation&quot;/&gt;<br><br>    &lt;target<br>        android:name=&quot;@string/play_icon_bottom_path_name&quot;<br>        android:animation=&quot;@animator/bottom_play_to_pause_animation&quot;/&gt;<br>&lt;/animated-vector&gt;</pre><p>The AnimatedVectorDrawable references the <em>play_icon.xml</em> and applies all the animation on the different parts</p><p>These animations are stored in the <em>animator</em> folder</p><p>For example the <em>rotate_90_animation.xml </em>animation</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;objectAnimator<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:duration=&quot;@integer/animation_duration&quot;<br>    android:interpolator=&quot;@android:anim/accelerate_decelerate_interpolator&quot;<br>    android:propertyName=&quot;rotation&quot;<br>    android:valueFrom=&quot;0&quot;<br>    android:valueTo=&quot;90&quot;<br>    android:valueType=&quot;floatType&quot;/&gt;</pre><p>If you want to check out the full source code you can take a look at the repository on Github.</p><p><a href="https://github.com/timrijckaert/FloatingMusicActionButton">timrijckaert/FloatingMusicActionButton</a></p><h3>Custom View</h3><p>Now our radio player app is able to stream ondemands and live radio.<br>That means we have two possible states the icon can animate to.<br>It also means we can animate back to the play icon when a stream is stopped or an ondemand was paused.</p><p>I decided to make a custom FloatingActionButton that does just that.</p><p>Add the FloatingActionButton to your layout and chose your mode with <strong>app:mode. </strong>You have the option between <strong>playToPause </strong>and <strong>playToStop</strong>.</p><pre>&lt;be.rijckaert.tim.animatedvector.FloatingMusicActionButton<br>    android:src=&quot;@drawable/play_to_pause_animation&quot;<br>    android:layout_width=&quot;wrap_content&quot;<br>    app:backgroundTint=&quot;@color/colorAccent&quot;<br>    <strong>app:mode=&quot;playToPause&quot;</strong><br>    android:layout_height=&quot;wrap_content&quot; /&gt;</pre><p>You can change the behavior dynamically by calling</p><pre>val musicFab= fab<em> </em>as FloatingMusicActionButton<br>musicFab.setMode(FloatingMusicActionButton.Mode.PLAY_TO_STOP)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88a9df956d20" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>