<?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[by MWM - Medium]]></title>
        <description><![CDATA[We pack cutting-edge technology into creative experiences accessible to everyone - Medium]]></description>
        <link>https://medium.com/mwm-io?source=rss----7ba680d79ad5---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>by MWM - Medium</title>
            <link>https://medium.com/mwm-io?source=rss----7ba680d79ad5---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:49:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/mwm-io" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building World’s First AI Coloring Pages Generator: A Technical and Creative Journey]]></title>
            <link>https://medium.com/@MWM.io/building-worlds-first-ai-coloring-pages-generator-a-technical-and-creative-journey-4077f97405ed?source=rss----7ba680d79ad5---4</link>
            <guid isPermaLink="false">https://medium.com/p/4077f97405ed</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[coloring]]></category>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[drawing]]></category>
            <dc:creator><![CDATA[MWM]]></dc:creator>
            <pubDate>Wed, 12 Apr 2023 11:16:31 GMT</pubDate>
            <atom:updated>2023-04-12T11:16:31.648Z</atom:updated>
            <content:encoded><![CDATA[<h3>Our approach to building World’s first AI coloring pages generator: A Technical and Creative Journey</h3><p>by Thomas Jacquemin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CyUxoasNwjn758Q1uhQlzQ.png" /><figcaption><a href="https://colorpop.ai/"><strong>Try Color Pop AI</strong></a></figcaption></figure><p><em>Disclaimer. This article represents our initial approach to the feature and should be considered a starting point. Since its publication, our methods and technology have evolved. We are committed to providing regular updates on our progress and improvements as we continue to advance the capabilities of Color Pop AI.</em></p><p>At MWM, we closely follow the latest technological advancements related to creativity. In the field of image generation, we have seen a tremendous increase in the capabilities of “generative models” in recent years. These AI models, trained on large datasets, capture the essence of the underlying data and become capable of generating new samples. Recent works have coupled generative capabilities with large language models that focus on written text comprehension, resulting in a fascinating form of interactivity: the generation of an image can now be conditioned on a sentence formulated by the user. This means it’s possible to influence the model in its generation process, as the model is trained to take into account the input text request.</p><h3>The birth of Color Pop AI</h3><p>It didn’t take long for a large community of AI enthusiasts to identify the creative power of these new tools, bringing AI-generated art under the spotlight. At MWM, we wanted to join in, and had already tried to get results with older frameworks like CLIP+VQGAN, which allowed us to obtain images recognizable by their abstract and evocative style. However, diffusion models made it possible to reach a new step in terms of speed and generation quality.</p><p>While the Machine Learning team worked on the technical specifications required for exploiting such models, the idea of applying these technologies to the <a href="https://colorpop.ai/">Color Pop</a> app originated from MWM’s designers who were well-aware of these new trends. Using AI to automatically generate coloring drawings came from the alliance of both technical and creative minds.</p><h3>How it works</h3><p>We applied these generation models in the context of coloring book drawing creation. Although our Color Pop app has already enabled thousands of users daily to express their creativity by coloring drawings from a vast predefined collection, what if a user wants to color something not available nor in any digital or physical form? For instance, what if they want to color their own creative ideas, such as a DJ cat or cat riding a motorbike?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dSkjpkF98E5MFArRdOiXGg.png" /></figure><p>The generative models made it possible for users to generate their own drawings and bring their own ideas by addressing the AI directly. Over the last few months, we have been working to provide our users with this on-the-fly drawing generation system, which is fully compatible with the existing drawing kit developed by the MWM mobile rendering team. Each generation being unique, users can now add their creations to their collection, color them, and share them with the world.</p><p>The deep learning model we use is called Stable Diffusion. It has been fine-tuned on a substantial coloring drawing dataset. When a Color Pop user sends a request to the service, four propositions are generated by the AI on our servers. A final post-processing step is applied to clean, upscale the resolution, and convert the image for our custom drawing kit that we developed for the mobile application.</p><h3>Challenges and solutions</h3><p>The first challenge was achieving a good level of quality, with some homogeneity of style regarding the coloring areas. They must be large enough and well-defined to be pleasant to color. Adding an ML feature to an existing application with tens of thousands of daily users is not straightforward. The AI model capable of generating the drawings is resource-intensive, and specific deployment strategies had to be put in place to quickly deliver four different images per request to all users in the world while avoiding unnecessary and costly server overload.</p><p>To address these challenges, we trained the model on a large dataset of internal manually curated artworks, with emphasis on quality first. The generative model was then guided to the desired specific drawing style, again with fine-tuning on a large collection of coloring book pages, that we acquired during the years of Color Pop existence.</p><p>As this project proved to be broad in scope, we also approached it as a way to further strengthen our internal pipelines and processes, including data collection, tracking and validation of experiments related to the models, integration within MWM’s custom services and infrastructures, model serving optimization, infrastructure scalability, and production monitoring.</p><h3>The future of Color Pop</h3><p>As we look to the next version of Color Pop, our main goal is to continuously improve the generation results to provide an even better coloring experience for our users. This includes working on achieving cleaner and smoother lines, which can be achieved by gathering more data and conducting further experimentation around the ML generative models. We also plan to keep up with the latest research in the field and update our service with better models as they become available.</p><p>In terms of product features, we have some exciting ideas in the works. One possibility is to offer users the ability to generate coloring pages based on their own faces, which would add a new level of personalization to the app. We are also exploring an “outpainting” feature, which would allow users to generate even larger canvases by generating extensions of the original drawing. While these ideas are still in the research phase, we are excited about the potential they hold for expanding the possibilities of Color Pop and giving users even more creative tools to work with.</p><p>About the author<br><a href="https://www.linkedin.com/in/jacquemin-thomas/">Thomas Jacquemin</a>, Machine Learning Engineer at MWM</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4077f97405ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Crafting Custom Path Formatting in IntelliJ File Templates for Android Development]]></title>
            <link>https://medium.com/mwm-io/crafting-custom-path-formatting-in-intellij-file-templates-for-android-development-c93c4c33689d?source=rss----7ba680d79ad5---4</link>
            <guid isPermaLink="false">https://medium.com/p/c93c4c33689d</guid>
            <category><![CDATA[file-templates]]></category>
            <category><![CDATA[basics]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[code-generation]]></category>
            <category><![CDATA[intelij-idea]]></category>
            <dc:creator><![CDATA[Marc Picone]]></dc:creator>
            <pubDate>Wed, 22 Mar 2023 08:44:20 GMT</pubDate>
            <atom:updated>2023-08-14T07:27:50.987Z</atom:updated>
            <content:encoded><![CDATA[<h4>Supercharge Your Workflow: A Step-by-Step Guide to Advanced File Templates</h4><h4>Advanced IntelliJ File Templates: Templates with multiple files and folders</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RqwMvw-dzmUk2EuiBZwQWw.png" /></figure><h3>Introduction</h3><p>Creating files and folders in a project can be a repetitive and time-consuming task, especially when following a specific architecture pattern. However, <a href="https://www.jetbrains.com/help/idea/using-file-and-code-templates.html"><strong>IntelliJ File Templates</strong></a> can automate this process and save you a lot of time.</p><p>In this article, we’ll show you how to create complex templates with multiple files and folders, using IntelliJ File Templates.</p><p>Moreover, file templates promote a shared understanding of best practices by providing predefined file structures that the team can adopt together.</p><p>So let’s dive in and take your IntelliJ File Template game to the next level!</p><h3>Link</h3><h4>Articles :</h4><ul><li><a href="https://medium.com/@piconemarc/mastering-intellij-file-templates-for-complex-android-views-a-guide-to-multiple-file-creation-with-968b4c82b9f4">Mastering IntelliJ File Templates for Complex Android Views: A Guide to Multiple File Creation with MVP and Layouts (Advance)</a>.</li><li><a href="https://medium.com/@piconemarc/creating-custom-room-database-templates-with-intellij-a-comprehensive-guide-for-android-developers-70e8dcdcbbe1">Creating Custom Room Database Templates with IntelliJ: A Comprehensive Guide for Android Developers (Expert)</a>.</li><li><a href="https://medium.com/@piconemarc/efficient-code-organization-with-file-templates-strategies-for-code-factorization-and-consistency-da158335ecbc">Efficient Code Organization with File Templates: Strategies for Code Factorization and Consistency</a>(Expert)</li></ul><h4>Gist :</h4><ul><li><a href="https://gist.github.com/marcpicone/54f2ab28e53b6e35e36e93ab45befa36">RootPath</a></li></ul><h4>1. Introduction to Custom Path Formatting</h4><p>Let’s start by creating a simple Kotlin class file using IntelliJ’s File Templates.</p><p>To create a new template, navigate to “File” &gt; “New” &gt; “Edit File Template…” in the main menu. Select the “Files” tab under “File and Code Templates” and click the “+” button to create a new file template.</p><p>In the “Name” field, enter a name for your template that will identify it in the “New” menu.</p><p>You can use the <strong>${NAME}</strong> variable in the “File name” field and select the extension for the file, such as kt.</p><p>Once you’ve created your first file template, you can click “OK”, and the IDE will propose the creation of your file template with the name you specified when creating a new file.</p><p>To create a folder and organise your file in a package, you can add the package name to the “File name” field, separated by a slash. This will create a folder with the specified package name and place your file inside it.</p><p>For example, you can enter <strong>my_package/${NAME}</strong> in the “File name” field. This will create a package called “my_package” and a file with the name of your choosing.</p><p>Now, let’s take a look at how we can make this process even more efficient by using custom path formatting with Velocity Template Language.</p><h4>2. Velocity Template Language</h4><p><a href="https://velocity.apache.org/engine/1.7/user-guide.html">Velocity Template Language</a> (VTL) is a Java-based language that provides several useful methods for writing templates. Even predefined variables like <strong>${NAME}</strong> use VTL.</p><p>Let’s assume that the <strong>${NAME}</strong> variable no longer stands for the file name in CamelCase, but instead, it represents the package name in snake_case. We want our path to be the package name provided in snake_case followed by the file name in CamelCase.</p><p>To accomplish this, we can use the StringUtils class, which contains the removeAndHump method. Our new path would look like this:</p><pre>${NAME}/${StringUtils.removeAndHump(${NAME}, &quot;_&quot;)}</pre><p>With this template, the IDE will prompt you to enter the file name, but instead of entering the file name in CamelCase, you’ll enter the package name in snake_case, and the IDE will create the package with the provided name and attach the file in CamelCase.</p><p>You can also hardcode a string after the path. For example, if you want your file to be a view, you can add it this way:</p><pre>${NAME}/${StringUtils.removeAndHump(${NAME}, &quot;&quot;)}View</pre><p>Now, let’s create another package with its own file.</p><h4>3. Create the layout file</h4><p>To continue with our example, let’s say we need to create a custom layout for a view in our Android app. While we could hardcode the path of our app’s res folder to create the layout file, we want a more adaptable solution that works for all apps. To achieve this, we’ll need to find a way to determine the number of folders we are from the app’s root folder when creating the template.</p><p>Thankfully, IntelliJ provides a variable called <strong>${PACKAGE_NAME}</strong>, which gives us the current file’s package name separated by dots. While this variable is typically used to fill in the package name at the top of a file, we can use it to determine the path we need to create our layout file.</p><p>To do this, we’ll create a new snippet in the “Include” tab of the template editor called “RootPath”.</p><p>This script initialises variables that we’ll use to construct the path.</p><p>The foreach loop splits the <strong>${PACKAGE_NAME}</strong> variable on dots, and for each iteration, we add “<strong>../</strong>” to the <strong>$rootRelativePath</strong> variable to navigate up one folder in the root folder.</p><p>Once the loop completes, we check if it’s the last iteration and concatenate <strong>$endRootPath</strong> to access the “root” folder.</p><p>Finally, we call <strong>$rootRelativePath</strong>, which gives us the desired result and allows us to create a secondary package or navigate to other desired folders within the package.</p><p>Here is the updated code for the “RootPath” snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4896b44b6cb9ff507b436298bd829d97/href">https://medium.com/media/4896b44b6cb9ff507b436298bd829d97/href</a></iframe><p><strong>Note that there should be no spaces at the beginning or end of every line as this can cause issues with package creation.</strong></p><p>To create a child template for our custom layout, select the file template and click on the “Add New Child Template” button on the right of the “+” button. In the child template file name, enter the following:</p><pre>#parse(&quot;RootPath.kt&quot;)/res/layout/${NAME}</pre><p>Make sure to set the extension as XML.</p><p>With this template, you can now create both the folder and file for your custom layout in a quick and efficient manner.</p><h3>Conclusion</h3><p>In this guide, we have learned how to use file templates to automate the creation of Android app components. By using variables such as <strong>${PACKAGE_NAME}</strong>, we can create adaptable solutions that work for any app.</p><p>We have also seen how to use the <a href="https://velocity.apache.org/engine/1.7/user-guide.html#set"><strong>#set</strong></a> and <a href="https://velocity.apache.org/engine/1.7/user-guide.html#foreach-loop"><strong>#foreach</strong></a> directives to create a custom path and how to create a child template for a custom view.</p><p>By automating this process, you can save time and promote best practices across your team. With these techniques, you can quickly create new files and folders that adhere to your architecture pattern without worrying about the directory structure.</p><p>If you want to take your file template skills to the next level, check out my other articles on <a href="https://medium.com/@piconemarc/mastering-intellij-file-templates-for-complex-android-views-a-guide-to-multiple-file-creation-with-968b4c82b9f4"><strong>creating a template for a custom view with MVP and a layout template</strong>,</a> and a more complex example on <a href="https://medium.com/@piconemarc/creating-custom-room-database-templates-with-intellij-a-comprehensive-guide-for-android-developers-70e8dcdcbbe1"><strong>templating Room database and Room entity</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c93c4c33689d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/crafting-custom-path-formatting-in-intellij-file-templates-for-android-development-c93c4c33689d">Crafting Custom Path Formatting in IntelliJ File Templates for Android Development</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering IntelliJ File Templates for Complex Android Views: A Guide to Multiple File Creation with…]]></title>
            <link>https://medium.com/mwm-io/mastering-intellij-file-templates-for-complex-android-views-a-guide-to-multiple-file-creation-with-968b4c82b9f4?source=rss----7ba680d79ad5---4</link>
            <guid isPermaLink="false">https://medium.com/p/968b4c82b9f4</guid>
            <category><![CDATA[file-templates]]></category>
            <category><![CDATA[intelij-idea]]></category>
            <category><![CDATA[layout]]></category>
            <category><![CDATA[mvp]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Marc Picone]]></dc:creator>
            <pubDate>Wed, 22 Mar 2023 08:43:58 GMT</pubDate>
            <atom:updated>2023-08-14T07:27:33.483Z</atom:updated>
            <content:encoded><![CDATA[<h4>Supercharge Your Workflow: A Step-by-Step Guide to Advanced File Templates</h4><h3>Mastering IntelliJ File Templates for Complex Android Views: A Guide to Multiple File Creation with MVP and Layouts</h3><h4>Simplify Your App Architecture: Quick MVP and Layout Creation Using a Customisable File Template</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YOPqoYHiOGYoAEq9t1vyxg.png" /></figure><h3>Introduction</h3><p>Creating file templates in IntelliJ is a great way to save time and effort while developing Android applications.</p><p>In the first article of this series, we learned how to customise file and folder paths to our liking.</p><p>In this article, we’ll explore how to create custom file templates for MVP (Model-View-Presenter) architecture in an Android app.</p><p>We’ll use file templates to generate the required code and layouts automatically. In this article, we’ll take it a step further and create templates with multiple files and folders.</p><p>When building MVP architecture for an Android app, there are three primary components to consider: the View, the Presenter, and the Contract. Let’s create templates for each of these components.</p><h3>Link</h3><h4>Articles:</h4><ul><li><a href="https://medium.com/@piconemarc/crafting-custom-path-formatting-in-intellij-file-templates-for-android-development-c93c4c33689d">Crafting Custom Path Formatting in IntelliJ File Templates for Android Development (Basic)</a>.</li><li><a href="https://medium.com/@piconemarc/creating-custom-room-database-templates-with-intellij-a-comprehensive-guide-for-android-developers-70e8dcdcbbe1">Creating Custom Room Database Templates with IntelliJ: A Comprehensive Guide for Android Developers (Expert)</a>.</li><li><a href="https://medium.com/@piconemarc/efficient-code-organization-with-file-templates-strategies-for-code-factorization-and-consistency-da158335ecbc">Efficient Code Organization with File Templates: Strategies for Code Factorization and Consistency</a>(Expert)</li></ul><h4>Gists:</h4><ul><li><a href="https://gist.github.com/marcpicone/30c8b402196ec8d358cc75de86835a44">NameToCamelCase</a></li><li><a href="https://gist.github.com/marcpicone/faf331b55d8c4817b1003a02c5c58073">View</a></li><li><a href="https://gist.github.com/marcpicone/f6ce5f53984d2d9e1d828484e7df6b3e">Presenter</a></li><li><a href="https://gist.github.com/marcpicone/d8fff9a58597d09315e7b97727600921">Contract</a></li><li><a href="https://gist.github.com/marcpicone/09a96959afc4701302ee5a5e302794c3">Layout</a></li></ul><h4>Template ZIP file:</h4><ul><li><a href="https://github.com/marcpicone/file_template_custom_view_article">file_template_custom_view_article</a></li></ul><h4>1. The View.kt</h4><p>To create the View file template, we’ll use the same approach as in the previous article, using a path with variables. We’ll simplify the process by passing the variable for the View name in the include tab.</p><p>First, we’ll create an include template named “NameToCamelCase” that will extract the CamelCase method to keep flexibility. Set the extension to kt and fill the body with <strong>${StringUtils.removeAndHump(“${NAME}”, “_”)}</strong>.</p><p>Now, we can use this include template in the path to generate the name for the View. To do this, create a new template and name it “CustomView” in the files tab. The new path will be :</p><pre>${NAME}/#parse(&quot;NameToCamelCase.kt&quot;)View</pre><p>Remember to set the file extension to <strong>kt</strong>.</p><p>To start, declare the package name at the top of the file:</p><pre>#if (${PACKAGE_NAME} &amp;&amp; ${PACKAGE_NAME} != &quot;&quot;)package ${PACKAGE_NAME}.${NAME}<br>#end</pre><p>Next, add the required imports:</p><pre>import android.content.Context <br>import android.util.AttributeSet <br>import android.view.View <br>import android.widget.FrameLayout <br>import androidx.annotation.IdRes <br>import ${PACKAGE_NAME}.R</pre><p>Notice how we could easily get the R class and keep it available for every app.</p><p>Then we could add the class declaration using our parse directive.</p><pre>class #parse(&quot;NameToCamelCase.kt&quot;)View @JvmOverloads constructor( <br>    context: Context,<br>    attrs: AttributeSet? = null,<br>    defStyleAttr: Int = 0 ) : FrameLayout(context, attrs, defStyleAttr){<br> <br>    private val view = inflate(context, R.layout.${NAME}, this) <br>}</pre><h4>2. The Presenter.kt</h4><p>To create the Presenter file template, we’ll need to create a new child template. Fill the File Name field with :</p><pre>${NAME}/#parse(&quot;NameToCamelCase.kt&quot;)Presenter</pre><p>And set the extension to kt.</p><p>In the body, start by declaring the package name with:</p><pre>#if (${PACKAGE_NAME} &amp;&amp; ${PACKAGE_NAME} != &quot;&quot;)package ${PACKAGE_NAME}.${NAME}<br>#end</pre><p>Next, add the class declaration using our NameToCamelCase.kt template:</p><pre>class #parse(&quot;NameToCamelCase.kt&quot;)Presenter(<br> private val screen : #parse(&quot;NameToCamelCase.kt&quot;)Contract.Screen<br>) : #parse(&quot;NameToCamelCase.kt&quot;)Contract.UserAction {<br><br>}</pre><p>Notice how easy it is to format all our file names with just one include template. This is a powerful feature that can save a lot of time and effort!</p><h4>3. The Contract.kt</h4><p>For the Contract, create a new child template with the following settings:</p><p>File Name:</p><pre>${NAME}/#parse(&quot;NameToCamelCase.kt&quot;)Contract</pre><p>Extension: kt<br>Body:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fbb3e45fec116a763401ea1460781e2/href">https://medium.com/media/5fbb3e45fec116a763401ea1460781e2/href</a></iframe><p>Note that this template follows the same structure as the Presenter and View templates, using the NameToCamelCase include template to format the file name.</p><h4>4. The Layout.XML</h4><p>To create a new XML file, we’ll create a child template in Android Studio. We’ll use the <strong>RootPath</strong> template that we created earlier to generate the file name.</p><p>We fill the File name with :</p><pre>#parse(&quot;RootPath.kt&quot;)/res/layout/${NAME}</pre><p>set extension to xml.</p><p>And finally the body :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5714d01554216316523c90f03d33e9ee/href">https://medium.com/media/5714d01554216316523c90f03d33e9ee/href</a></iframe><p>This template will generate a new XML file with a merge tag and a UI Link comment. The file will be created in the appropriate layout folder based on the RootPath template.</p><p>Now you can easily create a custom view by using this template.</p><h4>Conclusion</h4><p>In conclusion, we have learned how to streamline our MVP architecture in Android by creating file templates for the Presenter, View, Contract, and XML files. By using templates, we can save time and reduce errors in our code.</p><p>While this article focused on the MVP architecture, the same principles can be applied to other architectures, such as MVVM or MVI. By creating file templates that match the architecture, we can quickly create new screens or features and ensure that they adhere to the chosen architecture.</p><p>By utilising file templates for the MVP pattern, we’ve learned how to standardise our code and improve productivity. But our template approach doesn’t stop there. In the next article, we’ll take it up a notch and dive into <a href="https://medium.com/@piconemarc/creating-custom-room-database-templates-with-intellij-a-comprehensive-guide-for-android-developers-70e8dcdcbbe1"><strong>creating templates for Room database entities and DAO repositories</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=968b4c82b9f4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/mastering-intellij-file-templates-for-complex-android-views-a-guide-to-multiple-file-creation-with-968b4c82b9f4">Mastering IntelliJ File Templates for Complex Android Views: A Guide to Multiple File Creation with…</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Custom Room Database Templates with IntelliJ: A Comprehensive Guide for Android Developers]]></title>
            <link>https://medium.com/mwm-io/creating-custom-room-database-templates-with-intellij-a-comprehensive-guide-for-android-developers-70e8dcdcbbe1?source=rss----7ba680d79ad5---4</link>
            <guid isPermaLink="false">https://medium.com/p/70e8dcdcbbe1</guid>
            <category><![CDATA[room-database]]></category>
            <category><![CDATA[intelij-idea]]></category>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[file-templates]]></category>
            <dc:creator><![CDATA[Marc Picone]]></dc:creator>
            <pubDate>Wed, 22 Mar 2023 08:43:43 GMT</pubDate>
            <atom:updated>2023-08-14T07:28:31.250Z</atom:updated>
            <content:encoded><![CDATA[<h4>Supercharge Your Workflow: A Step-by-Step Guide to Advanced File Templates</h4><h4>Elevate Your Android Development Workflow with Custom File Templates: A Room Database Walkthrough</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vbh-Koxxx4BG-iP5h3-uhw.png" /></figure><h3>Introduction</h3><p>Welcome to the third article in our series on using IntelliJ file templates. In the first article, we learned how to customise file and folder paths to our liking, and in the second, we explored how to use this customisation to quickly create an MVP structure for an Android app.</p><p>Now, in this article, we’ll take things even further and learn how to use file templates to create a Room database in Android Studio. But don’t worry, the goal here is not just to create a database — it’s to show you how to master file templates and leverage their power to automate repetitive tasks and speed up your development process.</p><p>So let’s dive in and learn how to take your file template game to the next level!</p><h3>Link</h3><h4>Articles:</h4><ul><li><a href="https://medium.com/@piconemarc/crafting-custom-path-formatting-in-intellij-file-templates-for-android-development-c93c4c33689d">Crafting Custom Path Formatting in IntelliJ File Templates for Android Development (Basic)</a>.</li><li><a href="https://medium.com/@piconemarc/mastering-intellij-file-templates-for-complex-android-views-a-guide-to-multiple-file-creation-with-968b4c82b9f4">Mastering IntelliJ File Templates for Complex Android Views: A Guide to Multiple File Creation with MVP and Layouts (Advance)</a>.</li><li><a href="https://medium.com/@piconemarc/efficient-code-organization-with-file-templates-strategies-for-code-factorization-and-consistency-da158335ecbc">Efficient Code Organization with File Templates: Strategies for Code Factorization and Consistency</a>(Expert)</li></ul><h4>Gists:</h4><ul><li><a href="https://gist.github.com/marcpicone/dc21cb224315ce650d18264155088e99">ArgToSnakeCase</a></li><li><a href="https://gist.github.com/marcpicone/4a2c8ff62585f68c7c002fb93da5d493">RoomDbEntitiesDeclaration</a></li><li><a href="https://gist.github.com/marcpicone/63c101b3434ad78e11196d31eca7d7a1">ArgToLowerCamelCase</a></li><li><a href="https://gist.github.com/marcpicone/6606e914ec33860ba8437028e225df54">NameToLowerCamelCase</a></li><li><a href="https://gist.github.com/marcpicone/05aead9f65cc85070aa3cf137d1d1636">Database</a></li><li><a href="https://gist.github.com/marcpicone/d9eca1af9dd8b8db20a3eeaf073642e7">Repository</a></li><li><a href="https://gist.github.com/marcpicone/8a5947be56bea8745d00262e7e4b925e">RepositoryImpl</a></li><li><a href="https://gist.github.com/marcpicone/acc1c9a8c910b110707e58d79e140775">Dao</a></li><li><a href="https://gist.github.com/marcpicone/99ffc2991d135c99323425a9b137b776">Entity</a></li><li><a href="https://gist.github.com/marcpicone/ac8a6da753ae0c4f1fa2f4fd3519649e">DTO</a></li></ul><h4>Template ZIP file:</h4><ul><li><a href="https://github.com/marcpicone/file_template_room_db_article">file_template_room_db_article</a></li></ul><h4>1. Room Database</h4><p>In this section, we’ll create a custom file template to create the Room database with our preferred package structure, entity imports, and DAO declarations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GBLiA5tvO1Z-P6nXlGYogw.png" /></figure><p>Let’s start by creating a new file template and naming it RoomDatabase. We want the Room database to be in a package named <strong>data/my_package_room_database/MyPackageRoomDatabase</strong>. We’ll use the <strong>NameToCamelCase</strong> template (<a href="https://medium.com/@piconemarc/mastering-intellij-file-templates-for-complex-android-views-a-guide-to-multiple-file-creation-with-968b4c82b9f4">Created in the second article</a>) to convert the file name to camel case.</p><p>In the body of the template, we’ll start with the usual package declaration:</p><pre>#if (${PACKAGE_NAME} &amp;&amp; ${PACKAGE_NAME} != &quot;&quot;)package ${PACKAGE_NAME}.$NAME<br>#end</pre><p>Now, we’ll fill in the necessary imports:</p><pre>import android.content.Context<br>import androidx.room.Database<br>import androidx.room.Room<br>import androidx.room.RoomDatabase</pre><p>We want to be able to have the entity and Dao imports already filled in the template. To do this, we’ll create a custom variable that will prompt the user for the entities they want to use in the database. We’ll assume that the entered value will be a comma-separated list of Entity names.</p><p>To create the custom variable, we’ll jump to the top of the template, before the package declaration, and enter the following code:</p><pre>#set($entitiesArray = ${StringUtils.split($ENTITIES_LIST,&quot;,&quot;)})<br>#if (${PACKAGE_NAME} &amp;&amp; ${PACKAGE_NAME} != &quot;&quot;)package ....</pre><p>This sets the value of <strong>$entitiesArray</strong> by splitting the $<strong>ENTITIES_LIST</strong> on the comma. Since $<strong>ENTITIES_LIST</strong> is not set, it will be prompted by the IDE when the template is created.</p><p>Now, we can use our list of entities to import their respective Dao and DTO classes. Here’s what that looks like:</p><pre>#foreach($entity in $entitiesArray )<br>#set($ARG1 = &quot;$entity&quot;)<br>import ${PACKAGE_NAME}.data.#parse(&quot;ArgToSnakeCase.kt&quot;)_repository.${ARG1}Dao<br>import ${PACKAGE_NAME}.domain.#parse(&quot;ArgToSnakeCase.kt&quot;).${ARG1}DTO<br>#end</pre><p>Here, we’re using the <strong>ArgToSnakeCase</strong> template to convert the entity names to snake case for use in the package names. This is a simple include template that uses the removeAndHump method. We’re also using the parse directive to include an undefined variable named <strong>$ARG1</strong> that allows us to set a name to pass into the removeAndHump method.</p><p>Let’s create the <strong>ArgToSnakeCase</strong> template. We’ll create a new child template in the include tab, name it <strong>ArgToSnakeCase</strong>, and enter the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd38aeab64e5075c9b1c0f80cfe649f7/href">https://medium.com/media/cd38aeab64e5075c9b1c0f80cfe649f7/href</a></iframe><p>Now, we’ll create another include template to declare the entities. We’ll call this template <strong>RoomDbEntitiesDeclaration</strong>. In the template body, we’ll declare the entities by using the <strong>StringUtils.capitalizeFirstLetter</strong> method to capitalise the entity names and concatenate them with a hardcoded “DTO::class”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b66d0e1f5bb2fbd0fae5965e00304c2/href">https://medium.com/media/8b66d0e1f5bb2fbd0fae5965e00304c2/href</a></iframe><p>Now, let’s use this template in our RoomDatabase file template. Here’s what the template looks like now:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95e0907563a14afabf3518a9d5e776ee/href">https://medium.com/media/95e0907563a14afabf3518a9d5e776ee/href</a></iframe><p>Here, we’re using the Room database annotation to declare our database with the list of entities that we created in the <strong>RoomDbEntitiesDeclaration</strong> template. We’re also using the <strong>ArgToSnakeCase</strong> template to convert the entity names to snake case for use in the package names.</p><p>We could also see <strong>ArgToLowerCamelCase</strong> that is used to format variable name. Let’s create it in the include tab.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12235b995b5e01b6ff1f2b7c9c2610d5/href">https://medium.com/media/12235b995b5e01b6ff1f2b7c9c2610d5/href</a></iframe><p>That’s it for the Room database file template!</p><h4>2. Entity.kt</h4><p>To create a new file template for entities, we’ll call it RoomEntity and set its extension to .kt. We want the entity to be in a package named <strong>domain/entity_name/EntityName</strong>, so the file name should be:</p><pre>domain/${NAME}/#parse(&quot;NameToCamelCase.kt&quot;)</pre><p>In the body of the template, we’ll define the package and class declaration.</p><pre>#if (${PACKAGE_NAME} &amp;&amp; ${PACKAGE_NAME} != &quot;&quot;)package ${PACKAGE_NAME}.domain.${NAME}<br>#end<br>#parse(&quot;File Header.java&quot;)<br>data class #parse(&quot;NameToCamelCase.kt&quot;)(<br>    #formatArgumentListForDataClass()<br> )</pre><p>In order to populate our <strong>Entity</strong>, we will use a similar workaround as before and create a custom variable that we assume will be a list of (arg : type). This is where we introduce <a href="https://velocity.apache.org/engine/1.7/user-guide.html#velocimacros"><strong>Macros</strong></a>, which are used to create functions in the VTL world. Macros will be used here to format the name of the arguments over the snippet. Let’s take a look at the macro code:</p><pre>#macro( formatArgumentListForDataClass )<br>#set($argumentType = &quot;&quot;)<br>#set($foreach = &quot;&quot;)<br>#foreach($argumentType in ${StringUtils.split($ARGUMENT_LIST, &quot;,&quot;)})<br>val ${argumentType} #if($foreach.hasNext()), <br>#end<br>#end<br>#end</pre><p>Look at the way I add a coma and return to the Line if the list is not ended. The formatArgumentListForDataClass macro will format the argument list correctly, adding commas and returning to a new line if the list is not yet ended.</p><p>Now, let’s create a function to map the Entity to DTO. We’ll use a macro called formatArgumentListForDTOMapper to format the argument list.</p><pre>#macro( formatArgumentListForDTOMapper )<br>#set($argumentType = &quot;&quot;)<br>#set($argumentNameArray = [])<br>#set($foreach = &quot;&quot;)<br>#foreach($argumentType in ${StringUtils.split($ARGUMENT_LIST, &quot;,&quot;)})<br>#set($argumentNameArray = ${StringUtils.split($argumentType, &quot;:&quot;)})<br>$argumentNameArray.get(0) = this.$argumentNameArray.get(0) #if($foreach.hasNext()),<br>#end<br>#end<br>#end</pre><p>With this macro, we’ll create the entity body as follows:</p><pre>{<br>    fun toDTO(): #parse(&quot;NameToCamelCase.kt&quot;)DTO{<br>    return #parse(&quot;NameToCamelCase.kt&quot;)DTO(<br>       #formatArgumentListForDTOMapper()<br>    )<br> }</pre><p>We can now create a DTO template in a child template to our entity. We’ll set the file name to :</p><pre>domain/${NAME}/#parse(&quot;NameToCamelCase.kt&quot;)DTO</pre><p>and set its extension to .kt.</p><p>In the body of the template, we’ll define the package and class declaration, the tableName, and use the <strong>formatArgumentListForDataClass</strong> and <strong>formatArgumentListForModelMapper</strong> macros to create the argument list and the function to map the model to the DTO.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52b4b44c31e17dee90d22cd569120f0e/href">https://medium.com/media/52b4b44c31e17dee90d22cd569120f0e/href</a></iframe><p>Now that we have our entity created, it’s time to move on to the next step in our journey towards mastering file templates in IntelliJ — creating the repository.</p><h4>3. Repository.kt</h4><p>In this section, we will create a new include template called <strong>NameToLowerCamelCase</strong> that converts the variable $<strong>NAME</strong> to lower camel case. We will use this include template to create a new child template for our entity’s repository. The repository will have all CRUD methods, and we will also create an implementation of the repository.</p><p>First, let’s create the <strong>NameToLowerCamelCase</strong> include template.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aef3847eb5b13b4789f61fb5cf73fb24/href">https://medium.com/media/aef3847eb5b13b4789f61fb5cf73fb24/href</a></iframe><p>Now, let’s create a new child template for our entity’s repository. We want the file name to be <strong>data/package_name_repository/PackageNameRepository</strong>, so the file name is:</p><pre>data/${NAME}_repository/#parse(&quot;NameToCamelCase.kt&quot;)Repository</pre><p>The body will be:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ecea011374ab07e0e80f253dd77a76a/href">https://medium.com/media/5ecea011374ab07e0e80f253dd77a76a/href</a></iframe><p>And that’s done.</p><p>Now let’s create the implementation file.</p><p>The file name will be:</p><pre>data/${NAME}_repository/#parse(&quot;NameToCamelCase.kt&quot;)RepositoryImpl</pre><p>And the body:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac4bf7a700d61b16fc91396dc702ede9/href">https://medium.com/media/ac4bf7a700d61b16fc91396dc702ede9/href</a></iframe><p>In summary, we created a new include template <strong>NameToLowerCamelCase</strong> to convert the variable $<strong>NAME</strong> to lower camel case. We used this template to create a new child template for our entity’s repository, with all CRUD methods. Finally, we created an implementation of the repository, using the previously created child template and the necessary imports.</p><p>And the last, the DAO</p><p>The file name is:</p><pre>data/${NAME}_repository/#parse(&quot;NameToCamelCase.kt&quot;)Dao</pre><p>And the body :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf1706f3be03de9afa24e1c77ff9bc56/href">https://medium.com/media/bf1706f3be03de9afa24e1c77ff9bc56/href</a></iframe><p>This DAO file template defines methods to insert, query, update, and delete items in the database. It also includes the Dao annotation required by Room, as well as a companion object to define the table name.</p><p>Feel free to modify this template to suit your needs. Remember, the goal of this series of articles is to give you a step-by-step approach to deep diving into file templates, so don’t be afraid to experiment and try new things!</p><h3>Conclusion</h3><p>In conclusion, file templates can be incredibly useful for streamlining repetitive tasks in Android development, and we’ve seen how they can be used to create custom formatting for paths and generate complex views with multiple files. In this third article, we explored how to use file templates to generate code for a Room database, showing that the possibilities for template creation are only limited by one’s creativity.</p><p>While we’ve focused on specific use cases in this series of articles, it’s important to remember that file templates can be applied to a wide range of scenarios in Android development. They can help save time and reduce errors by automating repetitive tasks and allowing developers to focus on the more creative aspects of their work.</p><p>I hope that these articles have helped demystify file templates and encouraged you to explore their potential in your own projects.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70e8dcdcbbe1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/creating-custom-room-database-templates-with-intellij-a-comprehensive-guide-for-android-developers-70e8dcdcbbe1">Creating Custom Room Database Templates with IntelliJ: A Comprehensive Guide for Android Developers</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</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 use SwiftUI preview with UIView]]></title>
            <link>https://medium.com/mwm-io/how-to-use-swiftui-preview-for-uiview-404aad95f32e?source=rss----7ba680d79ad5---4</link>
            <guid isPermaLink="false">https://medium.com/p/404aad95f32e</guid>
            <category><![CDATA[swiftui-previews]]></category>
            <category><![CDATA[uiview]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Jonathan Mercandalli]]></dc:creator>
            <pubDate>Mon, 09 Jan 2023 09:50:39 GMT</pubDate>
            <atom:updated>2023-01-08T23:30:46.042Z</atom:updated>
            <content:encoded><![CDATA[<h4>SWIFT UI PREVIEW FOR UIVIEW</h4><h4>Avoid some runs on simulator or device to make UI</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w8fo8J4SZqlnIY2N2kqjtw.png" /></figure><p>Even if you do not want to convert your views to SwiftUI, you can use the Xcode preview of SwiftUI with UIView 👀</p><h3>1. UIView example</h3><p>Here a HelloWorld custom view displaying a UILabel with “HelloWorld” like the screenshot above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc033a063c61c82d0fc55cd89a9192f2/href">https://medium.com/media/cc033a063c61c82d0fc55cd89a9192f2/href</a></iframe><h3>2. PreviewProvider</h3><p>In order to use SwiftUI to display the Xcode preview, add the SwiftUI import.</p><p>Then, implement<br>- <strong><em>UIViewRepresentable</em></strong><em> </em>for<em> UIView<br>- </em><strong><em>UIViewControllerRepresentable</em></strong><em> </em>for<em> UIViewController</em></p><p>Finally, add a struct <strong><em>PreviewProvider</em></strong> to your class and tada 🎉<br>Opening the swift file in Xcode opens the preview.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8eeeace3bfea3cc6515db6c1f1f0378d/href">https://medium.com/media/8eeeace3bfea3cc6515db6c1f1f0378d/href</a></iframe><h3>3. Tips to go further</h3><ul><li><strong>[Preview resize]<br></strong>Inside the Preview struct, implement <a href="https://nilcoalescing.com/blog/CustomSizeForUIViewsWrappedInUIViewRepresentable/">sizeThatFits</a>.</li><li><strong>[PreviewMode]<br></strong>UIView will run on Xcode.<br>Means the <em>AppDelegate.applicationDidBecomeActive</em> and other iOS lifecycle methods will not be called.<br>So, some static fields or instances may not be reachable in preview mode.<br>Proposition: provide a boolean to the UIView to use mocks for the preview.</li><li><strong>[Crash]</strong><br>I didn’t find a way to get stacktrace when UIView is crashing in the preview mode.</li><li><strong>[Update preview]</strong><br>Close / Re-open the file reload the preview.</li><li><strong>[Show / Hide]</strong><br>Toggle via: <strong><em>Xcode menu</em></strong> &gt; <strong><em>Editor</em></strong> &gt; <strong><em>Canvas</em></strong></li></ul><p><em>Do not hesitate to comment if you have any idea to improve this article. (As an Android dev, iOS dev is pretty new for me ^^)</em></p><p><strong>Source</strong>: Thank you to <a href="https://medium.com/swlh/how-to-use-live-previews-in-uikit-204f028df3a9">Finsi Ennes article</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=404aad95f32e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/how-to-use-swiftui-preview-for-uiview-404aad95f32e">How to use SwiftUI preview with UIView</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IntelliJ File templates. Create multiple folders and files in one operation!]]></title>
            <link>https://medium.com/mwm-io/intellij-file-templates-create-multiple-folders-and-files-in-one-operation-86d1c5058516?source=rss----7ba680d79ad5---4</link>
            <guid isPermaLink="false">https://medium.com/p/86d1c5058516</guid>
            <category><![CDATA[file-templates]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[intelij-idea]]></category>
            <category><![CDATA[code-generation]]></category>
            <category><![CDATA[scripting]]></category>
            <dc:creator><![CDATA[Marc Picone]]></dc:creator>
            <pubDate>Fri, 16 Dec 2022 08:12:10 GMT</pubDate>
            <atom:updated>2023-03-22T08:19:16.464Z</atom:updated>
            <content:encoded><![CDATA[<h4>Optimize your development workflow</h4><h4>A developer’s perspective on utilizing IntelliJ file templates for faster code creation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*2lW3mm9MfV5i2zRBBK2hmA.gif" /></figure><p><strong>[Update 22/03/2023] -&gt; </strong><a href="https://medium.com/@piconemarc/crafting-custom-path-formatting-in-intellij-file-templates-for-android-development-c93c4c33689d"><strong>Crafting Custom Path Formatting in IntelliJ File Templates for Android Development</strong></a></p><p>Hi, as a developer, we are always looking for ways to streamline our processes and make our work more efficient. One tool that I have found to be incredibly helpful in achieving this is IntelliJ file templates. In this article, I’ll be sharing my experience with using file templates and how they have helped me improve my development workflow.</p><ul><li><strong>Level:</strong> Medior to senior developers.</li><li><strong>Goal:</strong> Create folders with file templates.</li><li><strong>Requirement</strong>: Android Studio IDE or any IntelliJ based IDE.</li></ul><h4><strong>1-Why this article?</strong></h4><p>Before Android Studio 4.1, we had the possibility to create our own template with multiple files and folders, but unfortunately, this feature is no longer available.</p><p>However, with the help of IntelliJ file templates and Velocity Template language, we can still achieve a similar outcome.</p><p><strong>External resources:</strong></p><ul><li><a href="https://riggaroo.dev/custom-file-template-group-android-studiointellij/">Here</a> is the solution that existed before <strong>Android Studio 4.1</strong>.</li><li>Here the actual <a href="https://www.jetbrains.com/help/idea/templates-with-multiple-files.html">IntelliJ</a> solution to create multiple files</li><li>Here is the <a href="https://velocity.apache.org/engine/1.7/user-guide.html">Velocity Template Language</a> documentation, that will help us to manipulate variables.</li></ul><h4><strong>2-</strong>Creating Folder with File Templates</h4><p>File templates in IntelliJ IDEs can be a powerful tool for automating repetitive and tedious tasks. One of the most useful features is the ability to create multiple files and folders in one operation.</p><p>To use file templates, you’ll first need to create a new template. In the file name, you can use variables such as <strong>${NAME}</strong> to represent the name of the file or folder you want to create.</p><p>For example, you can use the variable <strong>${PACKAGE}</strong> to represent the name of the package you want to create. The template file name could look like this:</p><p>`<strong>${PACKAGE}/${NAME}`</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VcL8XfirX4oURJOK" /></figure><p>When you create a new file using this template, the IDE will prompt you to fill in the values for <strong>NAME</strong> and <strong>PACKAGE</strong>.</p><p>You can also use the Velocity Template Language (VTL) to format variables. For example, if we want to name the package in snake case “<strong>feature_name_view</strong>” and the associated file in camel case “<strong>FeatureNameView</strong>”, we don’t want to have to enter the same name in snake case and camel case every time we create a new file template, even if they are the same.</p><p>So, we could assume that now the <strong>${NAME}</strong> is no more the file name, but the feature name, and this is where VTL comes in.</p><p>We can use VTL’s<strong> StringUtils.removeAndHump()</strong> method to format the variables. This method will take the <strong>${NAME}</strong> variable (<em>which represents the feature name</em>) and remove the underscores, effectively converting it to camel case. This way, we don’t have to manually enter the same name in different cases, the IDE will do it for us. The resulting path would look like this: feature_name_view/${StringUtils.removeAndHump(feature_name_view, ”_”)}FileType.</p><p>And that’s the way it could be wrote in our file template file name:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e1513d0690f8a474d89bf650138e36b/href">https://medium.com/media/4e1513d0690f8a474d89bf650138e36b/href</a></iframe><p>This will allow you to only enter the feature name in snake case and have the IDE automatically create the file name in camel case. If the folder already exists, only the files will be created in the existing folder, otherwise the folder and attached files will be created.</p><h4><strong>3-Create a secondary folder with a child template.</strong></h4><p>You can also use the Velocity Template Language (VTL) to create a secondary folder with its own files at the same time. It’s important to note that to create multiple files or folders you will need to create a child template on your file template.</p><p>For example, to create a folder in the same root folder, you can simply copy-paste the previous example and change the variable <strong>${NAME}</strong> to a new custom variable in your child template file name, like:</p><p>${ATTACHED_FEATURE_NAME}/${StringUtils.removeAndHump(${ATTACHED_FEATURE_NAME}, “_”)}</p><p>The IDE will ask for the two feature names and will determine the two attached files names, creating them in their respective folder.</p><p>To create a folder in another root folder, you can use the <strong>${PACKAGE_NAME}</strong> (given by the IDE) variable from the parent file to retrieve the root folder.</p><p>One way to navigate to another root folder is to split the <strong>${PACKAGE_NAME}</strong> variable from the parent file on the dot, then create a loop on the resulting array. On each iteration, we can add “<strong>../</strong>” to a path variable. This way, we can go up one folder level at a time, until we reach the desired root folder. Once we have the root folder, we can create a new folder or file in any location within that folder tree.</p><p>It’s possible to write this script in the file name of the file template, but it could be a long line and hard to understand. A better solution is to use the “Includes” tab to store this script and use the <strong>#parse(“FileName.extention”)</strong> directive in your file templates to include it where you need it. This way you can easily reuse this script and keep your templates clean and readable.</p><p>For example, you can use a script like this to retrieve the “res” folder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4896b44b6cb9ff507b436298bd829d97/href">https://medium.com/media/4896b44b6cb9ff507b436298bd829d97/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UuOZDBuFianPVpadMRxD9Q.png" /></figure><p>It’s important to note that there should be no spaces at the beginning or end of every line as this can cause issues with the creation of the package.</p><ul><li>The script begins by initializing all variables that will be used to create the path. This is necessary so that the Intellij IDE will not prompt the user to fill in the variable when creating the file.</li><li>Next, the script enters a foreach loop on the package name, which is split on the dot. The <strong>#set</strong> directive is used to set the value of the variable and avoid printing it. In the loop, on each iteration, “../” is added to the “$resRelativePath” variable, allowing the script to navigate up one folder in the root folder.</li><li>The script then checks if it is on the last iteration of the loop. If it is, it concatenates <strong>$endResPath</strong> to access the “res” folder.</li><li>Finally, the script calls the <strong>$resRelativePath</strong> variable, which is the desired result and can be used to create a secondary package or navigate to other desired folders within the package.</li></ul><p>Pretty cool, isn’t it? With this path we could now create a secondary package, and more if needed, with simply filling the package name.</p><p>In conclusion, file templates are a powerful tool in a developer’s toolbox. With a little bit of creativity and understanding of VTL, you can streamline your workflow and save time on repetitive tasks.</p><p>I hope you’ve seen the potential of the tips discussed in this article and how they can be applied to your own projects.</p><p>If you’re interested in seeing how I’ve used these techniques in my own work, check out my article “<a href="https://medium.com/mwm-io/the-power-of-file-templates-bd526bd815b2"><strong>The power of file templates</strong></a>.”</p><p>Enjoy, explore, and keep coding! 💪</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86d1c5058516" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/intellij-file-templates-create-multiple-folders-and-files-in-one-operation-86d1c5058516">IntelliJ File templates. Create multiple folders and files in one operation!</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The power of file templates.]]></title>
            <link>https://medium.com/mwm-io/the-power-of-file-templates-bd526bd815b2?source=rss----7ba680d79ad5---4</link>
            <guid isPermaLink="false">https://medium.com/p/bd526bd815b2</guid>
            <dc:creator><![CDATA[Marc Picone]]></dc:creator>
            <pubDate>Fri, 16 Dec 2022 08:11:47 GMT</pubDate>
            <atom:updated>2023-03-22T08:18:24.579Z</atom:updated>
            <content:encoded><![CDATA[<h4>OPTIMIZE YOUR DEVELOPMENT WORKFLOW</h4><h3>The Power of Custom File Templates: Simplify Development and Boost Efficiency</h3><h4>Streamline Your Development Workflow: Boost Productivity with Custom File Templates and Naming Conventions</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W4qKbCXwUGS1PlH1Jr0M0A.gif" /></figure><p><strong>[Update 22/03/2023] -&gt; </strong><a href="https://medium.com/@piconemarc/crafting-custom-path-formatting-in-intellij-file-templates-for-android-development-c93c4c33689d"><strong>Crafting Custom Path Formatting in IntelliJ File Templates for Android Development</strong></a></p><p>Hi, as developers, we all want to write clean, maintainable code that is easy to understand and modify.</p><p>However, we often find ourselves spending more time creating boilerplate code than actually solving problems.</p><p>In this article, I’ll share some tips and tricks that have helped me streamline my workflow and create more efficient code. By using templates and custom file naming conventions, you can save time and reduce errors while keeping your code organised and consistent.</p><p>Whether you’re a seasoned pro or just starting out, these tips can help make your development process smoother and more enjoyable.</p><p>We’ll explore a simple and efficient approach to generating files in a flat architecture.</p><p><strong>External resources:</strong></p><ul><li>Here is a <a href="https://www.evandemond.com/programming/wide-and-flat">short article on benefits of Flat Architecture</a>.</li><li>Here is a <a href="https://medium.datadriveninvestor.com/model-view-presenter-mvp-5c3439227f83">short Medium Article</a> on MVP.</li><li>Here is the actual <a href="https://www.jetbrains.com/help/idea/templates-with-multiple-files.html">intelliJ</a> solution to create multiple files.</li><li>Here is the <a href="https://velocity.apache.org/engine/1.7/user-guide.html">Velocity Template Language</a> documentation.</li><li>Here is my IntelliJ File template article. <a href="https://medium.com/@piconemarc/86d1c5058516">IntelliJ File template. Create multiple folders and files in one operation</a>.</li></ul><h4>2-How to Use File Templates and Velocity Scripts</h4><p>In Intellij IDE, you can access the Preferences window and search for “file templates” in the search bar to find the file templates section.</p><p>In this section, the “Files” tab is used to implement the file templates, while the “Include” tab is used to store reusable code snippets using the Velocity template language’s #parse directive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W_tvedlFBWznHej3eKL86g.png" /></figure><p>In my case, I created two Velocity scripts for my project. The first one, named “SnakeCaseToCamelCase,” helps to change the feature name from snake case to camel case.</p><p>The script is as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc8744298fad6797142222f465d92e9c/href">https://medium.com/media/fc8744298fad6797142222f465d92e9c/href</a></iframe><p>The second script, named “ResPath,” retrieves the “Res” folder to create the related layout. It is a bit more complex and involves several Velocity template language features:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4896b44b6cb9ff507b436298bd829d97/href">https://medium.com/media/4896b44b6cb9ff507b436298bd829d97/href</a></iframe><h4><strong>3-Files and Folders.</strong></h4><p>So, with this let’s create the simplest part. In the “Files” tab, just add a new file template. The Name is to retrieve the template when it will be created, for me it will be “CustomView”, the extension could be “java”, “xml”, or others, for me “kt”, and finally the file name give the name and here the package name of the files.</p><p>As the first file I want to create is the <strong>View</strong> one, the first file name looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b026b13d0cf93cf074db7c3cc16cf84f/href">https://medium.com/media/b026b13d0cf93cf074db7c3cc16cf84f/href</a></iframe><p>This will be the parent file and will create a folder at the root of the selected file. Here the <strong>“$NAME”</strong> stands for the feature name. This file will be the opened one when creating multiple file templates, so if you are interested in opening another one on creating the file template, pass the selected one as parent.</p><p>In order to have the good package name, just add “<strong>${NAME}</strong>” at the end of the top line.</p><p>You could fill the template with whatever you want as a common part.</p><p>Just as example, mine look like this, I love the way the “#parse” is used to auto fill the class name and more:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f657d8e89add62f510c91eecd6c74954/href">https://medium.com/media/f657d8e89add62f510c91eecd6c74954/href</a></iframe><p>Now that we have the parent file, let’s create the <strong>Presenter</strong> file template. On the CustomView file template, add a new child template. Here I just have to fill the file extension, always “kt” for me, and the file path. as I want the presenter to be created in the same folder that the view, I enter the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0d0ac13594792ef4eeba2f47cd1b459/href">https://medium.com/media/e0d0ac13594792ef4eeba2f47cd1b459/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WXW61YdB3B5kawHiVHnLiQ.gif" /></figure><p>Like this, as the folder already exists, it just creates the file with the good name. Simply hardcode the extra “Presenter” information at the end of the parse directive.</p><p>And last the <strong>Contract</strong> the same way, I create a new child template and pass the following in the file name:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a1bcd7ad0ce4147d6604a48937a8d66/href">https://medium.com/media/4a1bcd7ad0ce4147d6604a48937a8d66/href</a></iframe><p>Now the last file to create is the layout. I added a new child template and set extension to “xml”. As we already have the ResPath script, we just have to fill the file name with the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1997bfbd703d8fe4f324dcfea0968606/href">https://medium.com/media/1997bfbd703d8fe4f324dcfea0968606/href</a></iframe><p>And that’s all. Now we could create the three files and their folder plus the layout folder and file by just naming the feature name in snake case, and that’s pretty useful!</p><h4><strong>3-Bonus.</strong></h4><p>As I use the same name convention for every new file in a package, I could use the $PACKAGE_NAME to retrieve the feature name and change it in camel case.</p><p>In the include tab I add a new file template named FolderToCamelCase.</p><p>The only thing I have to do here, is to split the package name on dot, loop on the created array and on the last iteration, I am on the feature name.</p><p>So my script for this is the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1504ee92f1b86f4bc2ad7fb3032b8a65/href">https://medium.com/media/1504ee92f1b86f4bc2ad7fb3032b8a65/href</a></iframe><p>If I have to create a repository with this naming convention, I could create a file template and fill the file name like this:</p><p><strong>`#parse(“FolderToCamelCase.kt”)Repository`</strong></p><p>With this when you create a new file from an existing folder you no longer need to fill nothing, the IDE makes it for you. Coool!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bxTXmJ3AS29pq6UIYcpIaA.gif" /></figure><p>And of course we could create multiple files at the same time with the help of child templates.</p><p>I hope the time spent to read this article was useful for you and that you already know what you will template soon!!</p><p>Have a nice day!</p><p><strong>Enjoy, explore and keep coding !💪</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd526bd815b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/the-power-of-file-templates-bd526bd815b2">The power of file templates.</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generate Bill of Material (BOM) with maven-publish plugin]]></title>
            <link>https://medium.com/mwm-io/generate-bill-of-material-bom-with-maven-publish-plugin-f30b44ab5436?source=rss----7ba680d79ad5---4</link>
            <guid isPermaLink="false">https://medium.com/p/f30b44ab5436</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[bill-of-materials]]></category>
            <category><![CDATA[maven]]></category>
            <dc:creator><![CDATA[Torcheux Frédéric]]></dc:creator>
            <pubDate>Wed, 14 Dec 2022 14:34:52 GMT</pubDate>
            <atom:updated>2022-12-14T14:35:08.894Z</atom:updated>
            <content:encoded><![CDATA[<h4>Gradle</h4><h3>Generate Bill of Material (BOM) with Gradle <strong>maven-publish</strong> plugin</h3><h4>Simplify the life of your libraries’ clients by providing a Bill of Material</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SP41Ns74h3z9il_f4wefHg.jpeg" /><figcaption>One dependency to manage all your library versions</figcaption></figure><p>A <a href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms">Bill of Material</a> is a maven dependency that defines a list of libraries with their versions. The goal is to enumerate versions of libraries that work well together.</p><p>It’s the SDK developers’ responsibility to test the compatibility between their library versions.</p><p>By using a BOM, as a client of these libraries, you avoid compatibility issues so you have fewer tests to do because SDK developers have done.</p><p>The BOM dependency contains no code, no resources, only a <strong>.pom</strong> file with library versions.</p><p>Examples of well-known libraries with a BOM</p><ul><li><a href="https://github.com/square/okhttp#releases">OkHttp</a>: Java HTTP client (define versions for logging-interceptor, urlconnection…)</li><li><a href="https://firebase.google.com/docs/android/learn-more#bom">Android Firebase SDK</a>: App development platform (defines all the versions for Crashlytics, Analytics…)</li><li><a href="https://developer.android.com/jetpack/compose/setup#using-the-bom">Jetpack Compose</a>: Modern UI toolkit to develop native UI.</li></ul><h3>How to create and release a BOM</h3><h4>Where to write the logic</h4><p>To create and release a BOM, we create a new gradle module. This module only has a build.gradle(.kts) file, nothing else.</p><p>We use the <a href="https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:publications"><strong>publishing</strong></a> task from the <a href="https://docs.gradle.org/current/userguide/publishing_maven.html"><strong>maven-publish</strong></a> plugin to publish a BOM.</p><p>The <strong>publishing</strong> task and the <strong>declaration of which libraries are in the BOM</strong> are in this gradle module.</p><p>There are 2 ways to create a BOM:</p><ul><li>By using the <a href="https://docs.gradle.org/current/userguide/java_platform_plugin.html"><strong>java-platform</strong></a><strong> </strong>plugin. Works with Groovy DSL and Kotlin DSL.</li><li>By manually writing library versions in the generated <strong>.pom</strong> file. Works with Groovy DSL. I didn’t succeed in making it work with Kotlin DSL.</li></ul><h4>Scenario</h4><p>In the following example, we are a company called <em>MyLittleCompany. </em>This company develops several libraries to easily:</p><ul><li>send events</li><li>manage AB-tests</li><li>manage user authentication</li></ul><p><em>MyLittleCompany</em> provides a BOM to improve the developer experience of its client developers. No more risk of conflict between library versions.</p><h4>Project structure</h4><p>All these libraries are in the same project. A library is also called a kit. We have 4 gradle modules:</p><ul><li>event_kit</li><li>abtest_kit</li><li>authentication_kit</li><li>appkits: It’s the name of the gradle module dedicated to the BOM generation and release.</li></ul><h4>Method 1: Use the java-platform plugin to generate a BOM</h4><ol><li>Indicate that you use the <strong>java-platform</strong> plugin and also the <strong>maven-publish</strong> plugin.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10d325dd93f12fe2b0ccaab31fb87bb4/href">https://medium.com/media/10d325dd93f12fe2b0ccaab31fb87bb4/href</a></iframe><p>2. Define libraries that will be in the BOM.</p><p>We could define each library we want in the BOM one by one, but here, we prefer to add a small logic to always add all of them (except appkits itself).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c66c4e9b80ab45e3a960d097c7b8c2d/href">https://medium.com/media/7c66c4e9b80ab45e3a960d097c7b8c2d/href</a></iframe><p><strong>Constraints </strong>bloc allows to define dependencies with their versions, but these dependencies are only added in the client project if the project defines them.</p><p><strong>Api </strong>indicates that the dependency will be available during the compilation step.</p><p>3. Configure <strong>maven-publish </strong>plugin to do the release.</p><p>Dependencies declared above are added to the component <strong>java-platform</strong>. We must indicate that the publication will publish this component (L.14).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea43929983c51393c521a1abf1f703cd/href">https://medium.com/media/ea43929983c51393c521a1abf1f703cd/href</a></iframe><p>4. Last step to generate and publish your BOM, execute the following command that will release all modules with the maven-publish plugin setup:</p><pre>./gradlew publish</pre><h4>Method 2: Manually write library versions in the pom to generate a BOM</h4><ol><li>Configure <strong>maven-publish </strong>plugin to do the release.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fae369f4363eb7db8bea4d7caa9e774/href">https://medium.com/media/6fae369f4363eb7db8bea4d7caa9e774/href</a></iframe><p>2. Now, we can add to the previous code the following lines that override the generated <strong>.pom</strong> file and injects dependencies information.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33ff8c9690ed040c21f97cd953a3e66c/href">https://medium.com/media/33ff8c9690ed040c21f97cd953a3e66c/href</a></iframe><p>3. Last step to generate and publish your BOM, execute the following command that will release all modules with the maven-publish plugin setup:</p><pre>./gradlew publish</pre><h3>How to use the BOM in your project</h3><p>In your application <strong>build.gradle</strong>, you must use the keyword <a href="https://docs.gradle.org/current/userguide/platforms.html#sub:using-platform-to-control-transitive-deps"><strong>platform</strong></a> to define a BOM dependency.</p><p>After that, you don’t have to give a version for the libraries defined in the BOM.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40cddaa96b6d29a35b1ff4fa5813ebec/href">https://medium.com/media/40cddaa96b6d29a35b1ff4fa5813ebec/href</a></iframe><h3>Override a library version (at your own risk!)</h3><p>If you want to override a library version, you can define it like you usually define a library version. This one will override the one in the BOM.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd8da0f781901315f1e8199e5d4e4c69/href">https://medium.com/media/bd8da0f781901315f1e8199e5d4e4c69/href</a></iframe><h3>Conclusion</h3><p>If you are an SDK developer and your libraries work together and have independent versions, a way to improve developer experience is to provide a bill of material.</p><p>We saw 2 methods to do that:</p><ul><li><strong>java-platform: </strong>the easiest solution. With very few lines, we can generate a BOM containing the library versions present in the project.</li><li><strong>Manually writing library versions in the pom</strong>: Require a little bit more code but allows to declare anything we want in the BOM (because we directly write in the <strong>.pom </strong>file whatever we want), like a library’s version not present in the project.</li></ul><p>No matter which method you choose, in less than 30 minutes, you can significantly improve the life of your clients. You have no reason not to provide a BOM!</p><h3>Links</h3><ul><li><a href="https://docs.gradle.org/current/userguide/publishing_maven.html">Maven Publish plugin documentation</a></li><li><a href="https://docs.gradle.org/current/userguide/platforms.html#sub:bom_import">Gradle import Maven BOM documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f30b44ab5436" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/generate-bill-of-material-bom-with-maven-publish-plugin-f30b44ab5436">Generate Bill of Material (BOM) with maven-publish plugin</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memory leaks fix via Android Studio profiler ]]></title>
            <link>https://medium.com/mwm-io/memory-leaks-fix-via-android-studio-profiler-51cfcfcbe6d1?source=rss----7ba680d79ad5---4</link>
            <guid isPermaLink="false">https://medium.com/p/51cfcfcbe6d1</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[memory-leak]]></category>
            <category><![CDATA[android-profiler]]></category>
            <dc:creator><![CDATA[Jonathan Mercandalli]]></dc:creator>
            <pubDate>Fri, 09 Dec 2022 18:25:24 GMT</pubDate>
            <atom:updated>2023-09-19T09:33:47.854Z</atom:updated>
            <content:encoded><![CDATA[<h4>Android Studio Profiler</h4><h4>How to use profiler to find reasons of memory leak?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n9lUP2RhlErdpC6IcTnB9w.png" /></figure><h3>Introduction</h3><p><strong>What is a memory leak?<br></strong>When garbage collector cannot free memory.</p><p><strong>Symptom?</strong><br>When memory grow indefinitely, causing weak performances, ANR, or crashes.</p><p><strong>Main cause on Android?</strong><br>Activity destruction, for example when screen rotate.<br>When a reference of Activity is kept in a “static object”, the memory cannot be free.</p><h3>Example</h3><p>Here a leaking activity.</p><ul><li><em>listener</em> has a reference to the <em>MainActivity</em> via the lambda</li><li><em>onCreate</em> add the <em>listener</em> to a static <em>manager</em></li><li>So, <em>MainActivity</em> cannot be garbage collected</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/922ae85d6e38535390a5f8042b372d11/href">https://medium.com/media/922ae85d6e38535390a5f8042b372d11/href</a></iframe><p>At each screen rotation, new <em>Activity</em> is created. The manager is unique. The <em>manager set of listeners</em> will grow keeping activities alive and keeping <em>largeObject</em> alive.</p><p>Full project available here: <a href="https://github.com/Mercandj/memory-leak-android/blob/main/app/src/main/java/com/medium/MainActivity.kt">memory-leak-android</a>.</p><h3>Cause and non-cause of leak</h3><p><strong>What is a scope?</strong><br>A scope is a chain of reference.<br>A root reference is the reference of the scope that retain the scope to be free from the garbadge collector point of view.<br>A scope is considered as “static” when the root reference is kept on a “static” variable (like singleton).</p><p><strong>What cause leak?<br></strong>When “a reference or a transitive reference” of “an object with lifecycle we want to garbage collect” is kept from “a static scope or a scope that persist the object scope”.</p><p><strong>What do not cause leak?</strong><br>When 2 objects of the same scope are referencing one another.<br>For exemple, a reference from a “static scope” referencing to another object reference also on a “static scope” (two manager for instance).<br>For example, a view and the activity that created the view.</p><h3>Profiler Analysis</h3><p><strong>Measure</strong></p><ol><li>Open the profiler: “<em>AndroidStudio bottom bar”</em> &gt; “<em>Profiler”</em></li><li>Select your process: “<em>SESSIONS +</em>” &gt; “<em>Device</em>” &gt; “<em>App</em>”</li><li>Click the memory chart</li><li>Run the scenario doing the leak (<em>on the sample, screen rotation</em>)</li><li>Capture the heap bump</li><li>Inspect result</li></ol><p>The profiler automatically detect leaks with a ⚠️ icon 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDA_PjglhUuCkG_r_3utOw.png" /><figcaption>Profiler</figcaption></figure><p><strong>Tips to find leak reason #1 — Arrange by package<br></strong>Great to find only your classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O1cPSXzIAnTEv29Bm2Xpww.png" /><figcaption>Arrange by package</figcaption></figure><p><strong>Tips to find leak reason #2— Sort, Depth, Go to Instance</strong></p><ul><li>A. Check huge object by sorting</li><li>B. Find the reason with the reference tab and “nearest” checkbox</li><li>C. Navigate from reference to reference to find the reference hold</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HHjd40SNrD75DuFduHRoNg.png" /><figcaption>Sort retained size -&gt; Check references -&gt; Find reason</figcaption></figure><h3>Sources</h3><p>Highly inspired by this article <a href="https://medium.com/@umairkhalid786/the-easiest-way-to-detect-and-fix-memory-leaks-using-android-studio-profiler-tool-and-weakreference-cd7c212908a1">The easiest way to detect and fix memory leaks using Android Studio Profiler Tool and WeakReference ❤</a>.<br>Thank you <a href="https://medium.com/@umairkhalid786?source=post_page-----cd7c212908a1--------------------------------">Umair Khalid</a> ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51cfcfcbe6d1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/memory-leaks-fix-via-android-studio-profiler-51cfcfcbe6d1">Memory leaks fix via Android Studio profiler 👀</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Music co-creation with AI: an experiment]]></title>
            <link>https://medium.com/mwm-io/music-co-creation-with-ai-an-experiment-781b1bffeeb?source=rss----7ba680d79ad5---4</link>
            <guid isPermaLink="false">https://medium.com/p/781b1bffeeb</guid>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[music]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[MWM]]></dc:creator>
            <pubDate>Fri, 22 Jul 2022 14:30:10 GMT</pubDate>
            <atom:updated>2022-07-22T14:27:51.150Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FDwe3CfDJTac%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DDwe3CfDJTac&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FDwe3CfDJTac%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/e0dd1709626b4f008404f2aad6b4ab32/href">https://medium.com/media/e0dd1709626b4f008404f2aad6b4ab32/href</a></iframe><p>Using Machine Learning for music production has been a steady field of experimentation in the past years, notably Google’s Magenta project is working on new approaches to music production with the help of AI. So far the focus is mostly on desktop and web-based applications.</p><h3>ML Framework</h3><p>One of their early experiments in musical co-creativity was <a href="https://magenta.tensorflow.org/pianogenie"><em>Piano Genie</em></a>: A generative model for MIDI was controlled entirely by 8 input buttons, no matter which button was hit, the model mapped it the harmonically “correct” sounding keys on an 88 keys piano scale. Higher indexed buttons (meaning more to the right of a 8 button row) resulted in higher keys on the piano scale, lower indexed buttons in the opposite. This created a very convincing sounding output. The creators of the experiment, <a href="https://chrisdonahue.com/">Chris Donahue</a> et al. used 8 real buttons as inputs and a model running on a computer.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FYRb0XAnUpIk%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DYRb0XAnUpIk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FYRb0XAnUpIk%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/477500d0800944dd83faa25f5aa8366b/href">https://medium.com/media/477500d0800944dd83faa25f5aa8366b/href</a></iframe><p>We loved this simple but effective method to co-create with AI and ported the experience to the mobile device: <strong>MWM LAB 01</strong> was born.</p><p>In order to implement Piano Genie on mobile, we first re-trained the model with PyTorch, following the excellent <a href="https://github.com/chrisdonahue/music-cocreation-tutorial">Music co-creation tutorial given by Chris Donahue at ISMIR 2021</a>.</p><p>Piano Genie has an auto-encoder structure that encodes piano performances into a reduced latent space of 8 keys. The decoder learns to reconstruct the original performance from this space. Both encoder and decoder make use of RNNs (<a href="https://en.wikipedia.org/wiki/Recurrent_neural_network">Recurrent Neural Networks</a>) in order to capture meaningful relations between notes in the time domain. While the system is trained entirely end-to-end, we only use the decoder part at inference time, as the user will play on the 8 button keyboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WgbXC8p2NBk2eovZ.png" /><figcaption>Schema of the model’s architecture with the decoder part used in the app on the right</figcaption></figure><h3>Mobile Conversion</h3><p>After some test runs of the model, the results were promising and we decided to continue with the implementation. Our first approach was to convert it to CoreML, which did not work due to the large number of inputs and the sequential nature of the model. RNNs are usually harder to convert to CoreML and requires some modifications of the model.</p><p>Another way of porting this model to mobile is to use the PyTorch C++ API for iOS. What we have to do is to convert the model in its TorchScript format, that can to be run independently from Python and is therefore optimized for edge inference.</p><h3>Mobile Implementation</h3><h4>ML-Model Integration</h4><p>Running a TorchScript model on iOS is done with the help of LibTorch-Lite by PyTorch. They provide as well a <a href="https://youtu.be/amTepUIR93k">step-by-step tutorial</a>, which explains the core concepts for the setup and showcases an example. It takes a bit of tinkering with model inputs / outputs using the <a href="https://pytorch.org/cppdocs/">PyTorch C++ API</a> but is generally working well and running a performant inference.</p><h4>Implementation Challenges</h4><p>After connecting the MIDI-output of the model to our in-house audio engine, there was still some issues to be tackled.</p><p><strong><em>NoteOff</em></strong></p><p>For noteOff we decided to track how long the user presses a button and map the corresponding touchesEnded event to the noteOff of the generated output note. Done, that was nice and easy.</p><p><strong><em>Velocity</em></strong></p><p>Velocity on the other hand is a real problem on a mobile device as most devices do not track the pressure applied to the screen. Apple did that in earlier versions of the iPhone but abandoned 3D touch in newer phones. Without it is impossible to get an accurate velocity from a user touch. That said, it can be hacked. For our prototype implementation we estimated velocity by mapping the covered surface of each button per UITouch to a velocity scale from 0 to 127:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3211f7653daa22ebc424c43bc021680/href">https://medium.com/media/b3211f7653daa22ebc424c43bc021680/href</a></iframe><p>We assumed that in most cases a harder touch should cover more surface area on the screen than a lighter touch. After some experimentation the hack enabled a more expressive mode to play than without it, which justified keeping it for further iterations. Usually about 4 different velocity states can be detected with this method and the user can adjust naturally to this via the feedback in sound intensity.</p><p><strong><em>Simultaneous Finger Touches</em></strong></p><p>We ran as well into a hardware / firmware limitation. On an iPhone, only 4 finger touches will be tracked simultaneously. Once a 5th finger hits the screen, all touch events and their data are erased. On an iPad this is less of an issue, the finger limit is 11 touches. Despite our efforts to overcome this limitation, we could not push the boundaries here. A simple reminder in the onboarding screen of the app to try to play with a max of 4 fingers only had to suffice for the time being.</p><h3>Going Further</h3><p>To expand the existing use cases for the app, we decided to add two experimental modes Generative Co-Creation and HandTracking. We also added MIDI output integration into the app to allow the user to route the output to app-external instruments.</p><h4>Generative Co-Creation</h4><p>Generative Co-Creation is based on the simple fact that no matter which keys are pressed the model somehow makes sense out of it and it sounds harmonically correct. To help a user getting started with playing, especially those who are not familiar with the piano, a simple algorithm creates random button noteOn and noteOff presses with a random velocity within a certain range. These random button presses serve as the model input and are mapped to a 16th note quantization generated by the audio engine on a muted metronome track. If played back with a harp as instrument, the model output sounds surprisingly coherent — although after a while this generative soundscape of course lacks a bigger picture song structure. That said, it keeps the harmonics and feels overall like an ambient harp solo.</p><h4>Hand Tracking</h4><p>Hand Tracking has become easy to integrate thanks to Apple’s Vision framework. It offers a model inference for detecting Human Hand Pose right in Swift with a few lines of code and there is a helpful API <a href="https://developer.apple.com/videos/play/wwdc2020/10653/">walkthrough</a> from WWDC 2020. Super nice, thanks Apple 🙂</p><p>In our implementation we are tracking one of the upper joints of both middle fingers as the tracked normalized X-Y coordinates proved to be relatively accurate even without smoothing applied. Mapping those finger position values to buttons and generating clear sonic feedback is still tricky. To offer a more fine grained control over the input triggers, we retrained the model to 16 inputs. We preferred the results of the 8 button model as the 16 button model generated a lot of higher pitched notes. It proved to be a better choice still from a hand interaction perspective though. It doubles the amount of possible triggers, which turns out to be easier and more expressive to play if the hands of the user keep a distance of more than 40 cm to the phone. In our tests it felt a bit like playing an invisible harp. While NoteOn events are tracked successfully by detecting if the hand of the user is hovering over an input button on the UI, mapping noteOff events meaningfully proves to be hard. In the current implementation we hardcoded a note duration of 0.1 seconds per note to provide a fixed noteOff. This is far from ideal but works in most cases reasonably well for a rewarding playing behavior.</p><h4>MIDI Out</h4><p>Music apps are a lot more powerful when they can be integrated into various other system setups and creative ecosystems. Therefore the communication with other apps and music creation tools was the final step to tackle. We added a MIDI OUT service to the app for channeling the generated MIDI values to other iOS apps or via bluetooth or cable / camera-connection kit to hardware devices like synthesizers and DAWs.</p><p>We did not find a lot of resources out there that explain in detail how to send MIDI messages with the updated Apple MIDI UMP API. After some experimentation we put together some basic code that works. Hopefully that’s helpful for someone else out there struggling with this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c2df667a631689bf7867d70002fc907/href">https://medium.com/media/1c2df667a631689bf7867d70002fc907/href</a></iframe><p>NoteOff is similar using MIDI1UPNoteOff as the main built in function by Apple.</p><h4>Prototype UI</h4><p>For the final app store version we realized changes in the UI were needed. We redesigned the main interface and the settings screen to make navigating the prototype app easier:</p><p>The app uses a simple color coding system to guide the user along the different functions: Gray is for displaying information, Yellow can be tapped / activated, Green is tapped / active. The interface elements and fonts are designed to be simple, informative and clear. Organizing the inputs as a row of buttons was based on the original hardware version of Piano Genie.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m_GR5RGD1MLV9ME4-UcrFg.png" /><figcaption>Overview of the final UI</figcaption></figure><p>Here is another video from our MWM Lab workbench with some hardware synthesizer connected to it.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FS5uyVHA_cIA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DS5uyVHA_cIA&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed3795238f276c8b10467be60295d1e4/href">https://medium.com/media/ed3795238f276c8b10467be60295d1e4/href</a></iframe><h3>LAB 01 on App Store</h3><p>That’s probably all for LAB 01 — we hope you have fun with <a href="https://apps.apple.com/fr/app/lab-01/id1633254390">our prototype on the App Store</a> :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*s6OlkVDO2uY3hk0iFAPdNQ.png" /><figcaption>Scan to download LAB01 on iOS</figcaption></figure><p>And again big thanks to GoogleMagenta + PianoGenie team for the inspirational foundations !</p><h4>About MWM</h4><p>MWM is a creative apps publisher and the creator of Edjing, the most downloaded mobile DJ app in the world. Our team is working on a range of different products including music, photo, video and drawing apps. Make sure to check them out on the <a href="https://apps.apple.com/fr/developer/mwm/id452269707">App Store</a> and <a href="https://play.google.com/store/apps/dev?id=6775629480928024144">Play Store</a></p><p>We are hiring, don’t hesitate to consult our open positions at <a href="https://mwm.io/">https://mwm.io/</a></p><p><em>Written by Roland Arnoldt and Virgile Boulanger</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=781b1bffeeb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mwm-io/music-co-creation-with-ai-an-experiment-781b1bffeeb">Music co-creation with AI: an experiment</a> was originally published in <a href="https://medium.com/mwm-io">by MWM</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>