<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Soumya Kanti Kar on Medium]]></title>
        <description><![CDATA[Stories by Soumya Kanti Kar on Medium]]></description>
        <link>https://medium.com/@dev.soumyamob?source=rss-834c31fed971------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*YeWBLbACawRekopjJSulAw.png</url>
            <title>Stories by Soumya Kanti Kar on Medium</title>
            <link>https://medium.com/@dev.soumyamob?source=rss-834c31fed971------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 18:14:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dev.soumyamob/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Animating Views in Android]]></title>
            <link>https://medium.com/@dev.soumyamob/animating-views-in-android-69cf11717bf5?source=rss-834c31fed971------2</link>
            <guid isPermaLink="false">https://medium.com/p/69cf11717bf5</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-libraries]]></category>
            <category><![CDATA[android-animations]]></category>
            <dc:creator><![CDATA[Soumya Kanti Kar]]></dc:creator>
            <pubDate>Mon, 02 May 2022 15:09:32 GMT</pubDate>
            <atom:updated>2022-05-02T15:09:32.779Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MNtrotCXcwrg4CvV" /><figcaption>Photo by <a href="https://unsplash.com/@steve_j?utm_source=medium&amp;utm_medium=referral">Steve Johnson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Android has come a long way with respect to animating views. With the latest version of Android, physics based animations are also provided to make it more realistic and even fun to watch. Powerful classes are at the disposal of the developers to create fantastic animations. But, even with all of this, I felt maybe a small, simple to use library can be made for some basic animations which do not need too much to coding, can be chained together and even easy to look and understand.</p><p>With that in mind, I developed the ViewAnimator library. It for Android and has been written in Kotlin. The GitHub link is provided below.</p><p><a href="https://github.com/wwdablu/ViewAnimator">GitHub - wwdablu/ViewAnimator: Android library to perform simple animations with least code</a></p><p>So, before we begin, let us take an example to see what amount of code is needed to generate an output like the one shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*RpCvHWsGvzbLzEpAoZKrKg.gif" /></figure><p>Using ViewAnimator library we can achieve the same using the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6fe68a54c22649935ad3035539db9d9/href">https://medium.com/media/d6fe68a54c22649935ad3035539db9d9/href</a></iframe><p>So if we read the code, it says, the TextViewAnimator (which works on the TextView) to typewrite (animated way to typing the text) the string and then wait for 1000 milliseconds. After waiting, using the ImageViewAnimator (which works on the ImageView) set the image content and show a new image (R.drawable.ic_love), and in parallel typewrite another text. Once all of this is done, wait for 1000 milliseconds. Then, in a loop for 2 times, scale the ImageView showing the ImageView content (which seems like a heart beat).</p><p>The idea in here is that every View will have it specified ViewAnimator, for example TextView has TextViewAnimator. Each of the specific ViewAnimator extends from BaseViewAnimator. The BaseViewAnimator is responsible to having the common animations which are applicable to all the Views.</p><p>The specific ViewAnimator will have animations which are specific to that particular view. For example, typewrite animation is applicable for TextViewAnimator and flipAndSetImage is applicable only for ImageView.</p><p>The available APIs have been provided. Custom views can also be used as part of the ViewAnimator library. We need to extend the BaseViewAnimator library and implement the ViewAnimator interface.</p><p>You can always fork or submit your requests or PRs to the project. Do let me know if you have any ideas, would love to collaborate and work on open source Android libraries.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69cf11717bf5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Publishing Android library using Gradle 7.0 to Jitpack]]></title>
            <link>https://medium.com/wwdablu/publishing-android-library-using-gradle-7-0-to-jitpack-2f7cf1b484af?source=rss-834c31fed971------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f7cf1b484af</guid>
            <category><![CDATA[android-libraries]]></category>
            <category><![CDATA[jitpack]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Soumya Kanti Kar]]></dc:creator>
            <pubDate>Fri, 17 Sep 2021 05:44:22 GMT</pubDate>
            <atom:updated>2021-09-17T05:44:22.232Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aJYT7cB-OcsRYI6t" /><figcaption>Photo by <a href="https://unsplash.com/@ffstop?utm_source=medium&amp;utm_medium=referral">Fotis Fotopoulos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We always want to keep ourselves updated, and also our code. Updates being enhancements, newer features, performance improvements and breaking changes. Change is inevitable.</p><p>With Gradle 7.0 and upwards, using Jitpack requires some change on the application side. Following are the changes that are needed to successfully have a build in Jitpack.</p><p>The first is that of JDK11 support. For this, we need to create a file named <a href="https://github.com/wwdablu/GuidedEditText/blob/master/jitpack.yml">jitpack.yml</a> at the root of the repository and add the following content:</p><pre>jdk:<br>  - openjdk11</pre><p>Make the following change inside <a href="https://github.com/wwdablu/GuidedEditText/blob/master/GuidedEditText/build.gradle">library gradle</a>.</p><pre>plugins <strong>{<br>    </strong>id &#39;com.android.library&#39;<br>    id &#39;kotlin-android&#39;<br>    id &#39;maven-publish&#39;<br><strong>}</strong></pre><p>At the end of the gradle file put in the following changes:</p><pre>afterEvaluate <strong>{<br>    </strong>publishing <strong>{<br>        </strong>publications <strong>{<br>            </strong>release(MavenPublication) <strong>{<br>                </strong>from components.release<br>                groupId = &quot;your.package.name&quot;<br>                artifactId = &quot;your_lib_name&quot;<br>                version = &#39;lib_version&#39;<br>            <strong>}<br>        }<br>    }<br>}</strong></pre><p>Next, open <a href="https://github.com/wwdablu/GuidedEditText/blob/master/settings.gradle">settings.gradle</a> file and add maven along with the other repositories.</p><pre>dependencyResolutionManagement <strong>{<br>    </strong>repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)<br>    repositories <strong>{<br>        ...</strong><br>        maven <strong>{ </strong>url &#39;https://jitpack.io&#39; <strong>}<br>    }<br>}</strong></pre><p>Once of these changes are done, one up the terminal and execute the following command to verify that it is working fine.</p><pre>./gradlew publishReleasePublicationToMavenLocal</pre><p>It should start a gradle daemon and at the end you should be build successful. Once the build is confirmed, push the changes into GitHub, create a new release and watch Jitpack successfully build and have the library available to all the other developers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f7cf1b484af" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wwdablu/publishing-android-library-using-gradle-7-0-to-jitpack-2f7cf1b484af">Publishing Android library using Gradle 7.0 to Jitpack</a> was originally published in <a href="https://medium.com/wwdablu">wwdablu</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Guiding user input on EditText]]></title>
            <link>https://medium.com/wwdablu/guiding-user-input-on-edittext-fa4fa2e3f747?source=rss-834c31fed971------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa4fa2e3f747</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-libraries]]></category>
            <dc:creator><![CDATA[Soumya Kanti Kar]]></dc:creator>
            <pubDate>Wed, 15 Sep 2021 15:02:02 GMT</pubDate>
            <atom:updated>2021-09-16T08:43:43.779Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G7tBlVElY9iFv3Ae" /><figcaption>Photo by <a href="https://unsplash.com/@brett_jordan?utm_source=medium&amp;utm_medium=referral">Brett Jordan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We have all used EditText as is or an extended class of it, like AppCompatEditText in our Android application. In several scenarios, we had a requirement wherein the text provided by the user has to follow certain rules, for example, the length of the input string must of a certain characters in length. To address this need of guiding the user to follow a set of rule and providing the information, GuidedEditText is created.</p><p>Gradle declaration</p><pre>allprojects {<br>    repositories {<br>        ...<br>        maven { url &#39;https://jitpack.io&#39; }<br>    }<br>}<br><br>dependencies {<br>    implementation &#39;com.github.wwdablu:GuidedEditText:Tag&#39;<br>}</pre><p>You can check the latest version of the release from the GitHub page.</p><p><a href="https://github.com/wwdablu/GuidedEditText">GitHub - wwdablu/GuidedEditText: UI component that can be attached to an EditText view which shows guides(rules) which are needed to be satisfied to have a proper entry.</a></p><p>So even before we proceed, let us see how the view looks like after it is attached with an EditText view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*Ar7cf-t8vZ2NdBZ04aZCNw.gif" /><figcaption>GuidedEditText in action</figcaption></figure><p>The approach is that the developer needs to design some rules which is needed to be adhered by the user when providing the information. Hence, a rule definition has to be present. Likewise, the first thing that needs to be done is that an implementation of the RuleDefinition is required to be created.</p><pre>interface RuleDefinition {<em><br>    </em>fun follows(input: String, rule: Rule) : State<em><br>    </em>fun text(state: State) : SpannableString<br>}</pre><p>Now before we proceed with that those methods need to implement we need to understand that a Rule can be in one of these allowed states</p><pre>enum class State {<br>    <em>Satisfied</em>,<br>    <em>Unsatisfied</em>,<br>    <em>PartiallySatisfied</em>,<br>    <em>PendingValidation<br></em>}</pre><p>Satisfied — This means that the rule requirement has been met</p><p>Unsatisfied — This means that the rule requirement has not been met</p><p>PartiallySatisfied — This wherein a portion of the requirement is met</p><p>PendingValidation — This signifies that some asynchronous task needs to be performed before it can be said whether the rule has been met or not. This puts the rule validation in a pending state.</p><p>Now, the method follows, will be called when the library wants to validate whether the input string meets the requirement.</p><p>The method text, needs to provide what text is needed to be displayed to the current state of the rule. Let us see this with an example:</p><pre>class UserNameIsEmail : RuleDefinition {<br>    override fun follows(input: String, rule: Rule): State {<br>        return if(Patterns.<em>EMAIL_ADDRESS</em>.matcher(input).matches())<br>            State.<em>Satisfied<br>        </em>else<br>            State.<em>Unsatisfied<br>    </em>}<br><br>    override fun text(state: State): SpannableString {<br>        return if(state == State.<em>Satisfied</em>)<br>            SpannableString(&quot;Username is acceptable&quot;)<br>        else<br>            SpannableString(&quot;Username must be an email address&quot;)<br>    }<br>}</pre><p>So in the above example we can see that we have defined a rule wherein we say that the input to the EditText must conform it being an email address. If the input string matches then we say State.Satisfied, otherwise State.Unsatisfied. Similar to this we can make any number of rules that needs to be handled.</p><p>Once the RuleDefinition has been written, we need to create a Rule from it. We can also set the notify mechanism for the rule. The sample code to create a rule from a RuleDefinition is provided below:</p><pre>val userNameIsEmail = Rule(UserNameIsEmail())<br>    .setNotifyOn(RuleDefinition.Notify.<em>Change</em>)<br>    .setStateText(State.<em>Satisfied</em>, Color.parseColor(&quot;#f4f4f2&quot;))<br>    .setStateText(State.<em>Unsatisfied</em>, Color.parseColor(&quot;#f4f4f2&quot;))</pre><p>We can set colour for the text for each of the corresponding states. Now let us understand the notify mechanism.</p><pre>enum class Notify {<br>    <em>Change</em>,<br>    <em>Debounce<br></em>}</pre><p>Change — This means that the RuleDefinition needs to be notified as soon as there is a change in the EditText content.</p><p>Debounce — This means that the RuleDefinition will be notified after a certain period of time, once the user has stopped entering text. This value can be modified while calling setNotifyOn. The default value is 600ms.</p><p>We will create the layout wherein we will link the EditText view with the GuidedEditText component.</p><pre>&lt;EditText<br>    android:id=&quot;@+id/et_user_name&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;36dp&quot;<br>    android:background=&quot;@drawable/rounded_corner&quot;<br>    android:layout_marginStart=&quot;16dp&quot;<br>    android:layout_marginEnd=&quot;16dp&quot;<br>    android:paddingStart=&quot;8dp&quot;<br>    android:paddingEnd=&quot;8dp&quot;<br>    /&gt;<br><br>&lt;com.wwdablu.guidededittext.GuidedEditText<br>    android:id=&quot;@+id/get_user_name_input&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;wrap_content&quot;<br>    android:layout_marginStart=&quot;16dp&quot;<br>    android:layout_marginEnd=&quot;16dp&quot;<br>    android:textColor=&quot;@color/black&quot;<br>    app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>    app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>    app:layout_constraintTop_toTopOf=&quot;parent&quot;<br>    app:guideAnimate=&quot;true&quot;<br>    app:guideTextSize=&quot;6sp&quot;<br>    app:guideBackgroundImage=&quot;@drawable/guide_background_sample&quot;<br>    app:guideLinkedWith=&quot;@id/et_user_name&quot;<br>    /&gt;</pre><p>We can see the property guideLinkedWith, which then specifies the reference to the EditText view. Finally, we need to just add the rule to the GuidedEditText component.</p><pre>mBinding.userNameInput.addRule(userNameIsEmail)</pre><p>Wasn&#39;t it easy and fun? This would make the code much cleaner with separation of logic and view. Also it would guide the user to ensure that the requirements are matched.</p><p>As always the library source code is open. Please feel free to report issues and open feature tickets.</p><p><a href="https://github.com/wwdablu/GuidedEditText">GitHub - wwdablu/GuidedEditText: UI component that can be attached to an EditText view which shows guides(rules) which are needed to be satisfied to have a proper entry.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa4fa2e3f747" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wwdablu/guiding-user-input-on-edittext-fa4fa2e3f747">Guiding user input on EditText</a> was originally published in <a href="https://medium.com/wwdablu">wwdablu</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Heroku, NodeJS, Android == Bliss!]]></title>
            <link>https://medium.com/@dev.soumyamob/heroku-nodejs-android-bliss-799f34784196?source=rss-834c31fed971------2</link>
            <guid isPermaLink="false">https://medium.com/p/799f34784196</guid>
            <category><![CDATA[full-stack-developer]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Soumya Kanti Kar]]></dc:creator>
            <pubDate>Sun, 06 Oct 2019 22:21:15 GMT</pubDate>
            <atom:updated>2019-10-06T22:21:15.741Z</atom:updated>
            <content:encoded><![CDATA[<p>Before we begin, I always wanted to host my own REST services, even though mock, and wanted to write a simple end-to-end implementation. So without keeping this wish, a wish, I went ahead and got my coffee, my MacBook and put on a music.</p><p>The objective here is going to be to use NodeJS and host an end-point which will return me some data. This will be called from an Android application so showcase the frontend as well as the backend implementation and integration.</p><p>The entire code has been shared in GitHub.</p><p><a href="https://github.com/wwdablu/Mockpress">wwdablu/Mockpress</a></p><p><strong>Environment Setup</strong></p><p>While developing this implementation, following are the services, frameworks and softwares along with their versions used.</p><ul><li>Node (10.16.3)</li><li>NPM (6.11.3)</li><li>Git (2.21.0)</li><li>Android Studio (3.5.1)</li><li>Heroku (Free Tier)</li></ul><p>You can create a free Heroku account and install or update the softwares before we proceed.</p><p><strong>Heroku Setup</strong></p><p>I have installed the Heroku CLI using the installer provided for Mac OS. It is also available for Linux and Windows too. You can refer the link below.</p><p><a href="https://devcenter.heroku.com/articles/getting-started-with-nodejs#set-up">Getting Started on Heroku with Node.js</a></p><p>Once done, open up a terminal and add the command heroku login. This will open up a browser, login using you credentials and follow the instructions. Once done, you can close the browser window and you should be logged into the terminal.</p><p><strong>Create Project</strong></p><p>Create a folder, and type the command below. This will create the project.</p><p>npm init</p><p>Following the instructions to setup the project and generate the package.json. You can create a new entry point or keep the default to index.js. For this demo, we will rename it to server.js. The final package.json should have the following content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DbVpzSWrJlSE1qXkCD-1Aw.png" /><figcaption>Package.json content</figcaption></figure><p>We need to manually add the content inside scripts closure. It states that when the instance is run, it will execute the server.js file.</p><p>Now, we will add the Express module dependency. This can be done by the following command. This will download the node module on the folder.</p><p>sudo npm install express --save</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nt76B7x-Bl8k6ntrYUBJjA.png" /><figcaption>npm express installed</figcaption></figure><p>We are good till here, but this is just the setup. We have not yet written any code. But, we are going to do it now. We are going to create the server.js file which we had mentioned in the package.json as our entry point.</p><p>Below is the small piece of code that will be put in server.js.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f2552505261a4a496af3bad69bfacd9/href">https://medium.com/media/7f2552505261a4a496af3bad69bfacd9/href</a></iframe><p>Once this code is done, we will commit the same in git. For this I have used the GitHub client but you can also the terminal. Once this is done, we will move to the next step.</p><p>On the same terminal wherein we are doing all the work, in here we are now going to use the Heroku CLI and deploy the app that we have created. First we need to create a remote project in Heroku. For this we will be using the following command in the terminal.</p><p>heroku create</p><p>This will create a project and provide the details and also the domain endpoint on which the service will be hosted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tud-9cYZ4FXkidiY7FZiBg.png" /><figcaption>heroku create — Remote project created on which the code will be deployed</figcaption></figure><p>Perfect! Now, we will need to push the code to Heroku which will then be built and deployed on the URL which had been provided as the output of the create command by the Heroku CLI. To push, build and deploy the code, we need to provide the terminal command.</p><p>git push heroku master</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HrrMjzk6GAeVEznkZlUZ3Q.png" /><figcaption>Output of the code pushed, built and deployed in Heroku remote server</figcaption></figure><p>So, the build is done and the code has been deployed. To test the result, we will type the following command in the terminal. This will open a browser with the endpoint.</p><p>heroku open</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JiJ-l5mbzz_9PdqzNmQvQA.png" /><figcaption>Deployed code being executed</figcaption></figure><p>This is all good. But now let us create a separate path which will return list of vegetables, the price and also their image. We modify the server.js as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8e24f5c947e5fca54e737bc4a6520d9/href">https://medium.com/media/b8e24f5c947e5fca54e737bc4a6520d9/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*loqmLitS0vLm3AZ-czhRCA.png" /><figcaption>Vegetable prices endpoint.</figcaption></figure><p>This is all good, but can we not connect Heroku with GitHub. This will make it easier such that, whenever we push any code changes, Heroku then automatically fetch the latest code, build and deploy it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vj2HvdX16vsld4YtXPFQKQ.png" /></figure><p>This can be done by clicking on the Connect to GitHub option. I personally did not go ahead with this option was I do not wish to provide access to my private repositories. ;)</p><p>Now, we can consume this endpoint and make our Android application as we want. This concludes the basic approach which can be scaled as per the requirement, for example using MongoDB along. Do let me know what you think as always if you like then do give a clap. Till we meet again with another learning.</p><p><a href="https://github.com/wwdablu/Mockpress">wwdablu/Mockpress</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=799f34784196" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SimplyPDF — Create PDF in Android through code or JSON]]></title>
            <link>https://medium.com/wwdablu/simplypdf-create-pdf-in-android-through-code-or-json-d349052dd898?source=rss-834c31fed971------2</link>
            <guid isPermaLink="false">https://medium.com/p/d349052dd898</guid>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Soumya Kanti Kar]]></dc:creator>
            <pubDate>Sun, 19 May 2019 22:32:39 GMT</pubDate>
            <atom:updated>2021-10-29T07:27:48.668Z</atom:updated>
            <content:encoded><![CDATA[<h3>SimplyPDF — Create PDF in Android through code or JSON</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*53G98elhVMjwuALITjwNyg.jpeg" /></figure><p><strong>[Update]<br></strong>Version 2.x has been released since the last release of version 1.2.0. In here I have added several features, removed some and fixed several defects too. This article is updated based on Version 2.x.</p><p>Following are the list of changes which have been incorporated as part of Version 2.x release:</p><ul><li>Switched from Java to Kotlin</li><li>Min SDK has been increase from 22 to 23</li><li>Added the feature to add custom page modifiers like PageHeaders.</li><li>Feature to provide custom margin values from both code and JSON</li><li>Ability to add custom converts which can use custom composers via JSON</li><li>Margins and alignments have been fixed for all the native composers</li><li>Tables now support the addition of bitmaps via ImageCell.</li><li>JSONEngine has been made more modular to support custom nodes.</li><li>Composer specific tests have been moved out from MainActivity to respective classes.</li><li>Code restructuring</li><li>Dependent libraries have been updated</li><li>Bug fixes that were observed during testing</li><li>ShapeComposer has removed as it can be handled by ImageComposer directly.</li></ul><p><a href="https://github.com/wwdablu/SimplyPDF">wwdablu/SimplyPDF</a></p><p>Version 2.x contains several breaking changes, so it will not be a straight upgrade from the previous versions. Most of the code will remain the same but few changes will be required.</p><p>At first we need to create a PDF document on which the content will be written.</p><pre>simplyPdfDocument = SimplyPdf.with(this, fileToSaveIn)<br>    .colorMode(DocumentInfo.ColorMode.COLOR)<br>    .paperSize(PrintAttributes.MediaSize.ISO_A4)<br>    .margin(Margin(startMargin, topMargin, endMargin, bottomMargin)<br>    .pageModifier(PageHeader())<br>    .firstPageBackgroundColor(Color.WHITE)<br>    .paperOrientation(DocumentInfo.Orientation.PORTRAIT)<br>    .build();</pre><p>This will provide us with the object through which we can access the PDF document and perform actions on it. Internally it uses the PrintedPdfDocument provided by Android. SimplyPdfDocument provides additional methods and makes the PDF creation much simpler.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NBqFrzUnbzUAnybwIsS_oA.png" /></figure><p>SimplyPdfDocument also provide access to the default composers which will be discussed in the later part of the story. They can be accessed as following:</p><ul><li>simplyPdfDocument.text — To access the default TextComposer</li><li>simplyPdfDocument.image — To access the default ImageComposer</li></ul><p><strong>Composers</strong></p><p>Composers are classes which are used to render content in the PDF document. The library as of now provides three (2) UnitComposers and one (1) GroupComposer.</p><p>UnitComposers are those composers which provide a singular objective and is it the leaf node of the Composer tree. They are:</p><ul><li>TextComposer — Allows the developer to write text content in PDF</li><li>ImageComposer — Allows the developer to draw bitmap images</li></ul><p>GroupComposers on the other hand uses the objective of the UnitComposers and allow homogenous or heterogeneous objective. Currently it is:</p><ul><li>TableComposer — Allows the developers to render text and bitmap contents within a table format. They use TextCell and ImageCell for the purpose of rendering.</li></ul><p>A composer is also supported by its respective property class. The property class defines the property of the composer as to how should it behave. For example, it can be text color for the TextComposer.</p><p><strong>Composers and Properties</strong></p><p>Let us consider TextComposer. This allows the developer to write textual content in the PDF. Its supported property class is TextProperties.</p><pre>simplyPdfDocument.text.write(&quot;Hello World&quot;, TextProperties().apply {<br>    textSize = 12<br>    textColor = &quot;#000000&quot;<br>    typeface = Typeface.DEFAULT<br>})</pre><p>In here we are using the TextComposer to write the text SimplyPDF on the simplePdfDocument. The text will be of size 12, with black text color and default typeface. An operation performed using a default Composer must be provided with a Property object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wrx2KWV-Uf1xdA1GfXtKCg.png" /><figcaption>TextComposer</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uptn0QPsz1QfIxpmgCIJvg.png" /><figcaption>ImageComposer</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KOoxVqmSBlPqIxf2KbomRQ.png" /><figcaption>TableComposer</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXY12mpEAbt4s2N5fY7zkA.png" /><figcaption>TableComposer sample</figcaption></figure><p><strong>JSON Driven Approach</strong></p><p>This approach tries to simplify the process a bit more than writing more code. Here a JSON is required to be defined which will drive the process of PDF creation. Some of the benefits of this approach:</p><ul><li>No PDF generation related code is written in the application and hence it is entirely abstracted.</li><li>JSON can be obtained from remote server which provides the benefit of dynamic content update.</li><li>JSON can be used as template to replace placeholders and then use it to generate PDF.</li></ul><p>Consider the below JSON structure:</p><pre>{<br>    &quot;page&quot; : [<br>    {<br>        &quot;type&quot; : &quot;world&quot;<br>    },<br>        {<br>            &quot;type&quot; : &quot;setup&quot;,<br>            &quot;margin&quot; : {<br>                &quot;start&quot; : 125,<br>                &quot;top&quot; : 125,<br>                &quot;end&quot; : 125,<br>                &quot;bottom&quot; : 125<br>            },<br>            &quot;backgroundcolor&quot; : &quot;#C8C8C8&quot;<br>        },<br>        {<br>            &quot;type&quot; : &quot;header&quot;,<br>            &quot;contents&quot; : [<br>                {<br>                    &quot;type&quot; : &quot;text&quot;,<br>                    &quot;content&quot; : &quot;Simplypdf&quot;,<br>                    &quot;properties&quot; : {<br>                        &quot;size&quot; : 24,<br>                        &quot;color&quot; : &quot;#000000&quot;,<br>                        &quot;underline&quot; : false,<br>                        &quot;strikethrough&quot; : false,<br>                        &quot;alignment&quot; : &quot;ALIGN_CENTER&quot;<br>                    }<br>                },<br>                {<br>                    &quot;type&quot; : &quot;text&quot;,<br>                    &quot;content&quot; : &quot;Version 2.0&quot;,<br>                    &quot;properties&quot; : {<br>                        &quot;size&quot; : 20,<br>                        &quot;color&quot; : &quot;#000000&quot;,<br>                        &quot;underline&quot; : true,<br>                        &quot;strikethrough&quot; : false,<br>                        &quot;alignment&quot; : &quot;ALIGN_CENTER&quot;<br>                    }<br>                }<br>            ]<br>        }<br>    ],<br>    &quot;contents&quot; : [<br>        {<br>            &quot;type&quot; : &quot;text&quot;,<br>            &quot;content&quot; : &quot;Simplypdf developed by Soumya Kanti Kar&quot;,<br>            &quot;properties&quot; : {<br>                &quot;size&quot; : 24,<br>                &quot;color&quot; : &quot;#000000&quot;,<br>                &quot;underline&quot; : true,<br>                &quot;strikethrough&quot; : false<br>            }<br>        },<br>        {<br>            &quot;type&quot; : &quot;image&quot;,<br>            &quot;source&quot; : &quot;https://avatars0.githubusercontent.com/u/28639189?s=400&amp;u=bd9a720624781e17b9caaa1489345274c07566ac&amp;v=4&quot;<br>        },<br>        {<br>            &quot;type&quot; : &quot;text&quot;,<br>            &quot;content&quot; : &quot;Source code published in GitHub&quot;,<br>            &quot;properties&quot; : {<br>                &quot;size&quot; : 20,<br>                &quot;color&quot; : &quot;#000000&quot;,<br>                &quot;underline&quot; : true,<br>                &quot;strikethrough&quot; : false<br>            }<br>        },<br>        {<br>            &quot;type&quot; : &quot;newpage&quot;<br>        },<br>        {<br>            &quot;type&quot; : &quot;space&quot;,<br>            &quot;height&quot; : 125<br>        },<br>        {<br>            &quot;type&quot; : &quot;table&quot;,<br>            &quot;contents&quot; : [<br>                {<br>                    &quot;row&quot; : [<br>                        {<br>                            &quot;type&quot; : &quot;text&quot;,<br>                            &quot;content&quot; : &quot;Version&quot;,<br>                            &quot;width&quot; : 50,<br>                            &quot;properties&quot; : {<br>                                &quot;size&quot; : 24,<br>                                &quot;color&quot; : &quot;#000000&quot;,<br>                                &quot;underline&quot; : true,<br>                                &quot;strikethrough&quot; : false<br>                            }<br>                        },<br>                        {<br>                            &quot;type&quot; : &quot;text&quot;,<br>                            &quot;content&quot; : &quot;2.0.0&quot;,<br>                            &quot;width&quot; : 50,<br>                            &quot;properties&quot; : {<br>                                &quot;size&quot; : 24,<br>                                &quot;color&quot; : &quot;#000000&quot;,<br>                                &quot;underline&quot; : true,<br>                                &quot;strikethrough&quot; : false<br>                            }<br>                        }<br>                    ]<br>                },<br>                {<br>                    &quot;row&quot; : [<br>                        {<br>                            &quot;type&quot; : &quot;text&quot;,<br>                            &quot;content&quot; : &quot;Source Code Available in GitHub&quot;,<br>                            &quot;width&quot; : 100,<br>                            &quot;properties&quot; : {<br>                                &quot;size&quot; : 24,<br>                                &quot;color&quot; : &quot;#000000&quot;,<br>                                &quot;underline&quot; : true,<br>                                &quot;strikethrough&quot; : false<br>                            }<br>                        }<br>                    ]<br>                },<br>                {<br>                    &quot;row&quot; : [<br>                        {<br>                            &quot;type&quot; : &quot;image&quot;,<br>                            &quot;type&quot; : &quot;image&quot;,<br>                            &quot;source&quot; : &quot;https://avatars0.githubusercontent.com/u/28639189?s=400&amp;u=bd9a720624781e17b9caaa1489345274c07566ac&amp;v=4&quot;<br>                        }<br>                    ]<br>                }<br>            ],<br>            &quot;properties&quot; : {<br>                &quot;width&quot; : 1,<br>                &quot;color&quot; : &quot;#000000&quot;<br>            }<br>        }<br>    ]<br>}</pre><p>This JSON defines that the PDF document will contain the defined contents. This it is required to be provided SimplyPDF which will generate the document.</p><p>As usual the source code is available in GitHub. Do let me know if this helps you in your projects. This is sufficiently helpful in the project in which I am working. Thanks all again.</p><p><a href="https://github.com/wwdablu/SimplyPDF">wwdablu/SimplyPDF</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d349052dd898" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wwdablu/simplypdf-create-pdf-in-android-through-code-or-json-d349052dd898">SimplyPDF — Create PDF in Android through code or JSON</a> was originally published in <a href="https://medium.com/wwdablu">wwdablu</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lottie — Using it in Android]]></title>
            <link>https://medium.com/wwdablu/lottie-using-it-in-android-5bfbe8cd4ff7?source=rss-834c31fed971------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bfbe8cd4ff7</guid>
            <category><![CDATA[lottie]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-libraries]]></category>
            <dc:creator><![CDATA[Soumya Kanti Kar]]></dc:creator>
            <pubDate>Wed, 05 Dec 2018 23:22:57 GMT</pubDate>
            <atom:updated>2019-11-19T01:51:47.913Z</atom:updated>
            <content:encoded><![CDATA[<h3>Lottie — Using it in Android</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hrJ760Gu8gTV9YpcaBsMsg.png" /></figure><p>Lottie is a wonderful library provided by the devs from AirBnb. It provides a fantastic way to animate vector drawables. With this an endless opportunity is opened up to the other developers to spice up their application.</p><p>I have implemented a bottom navigation control using Lottie to animate the menu icons and provide some fun to it. The entire code has been shared here on GitHub:</p><p><a href="https://github.com/wwdablu/LottieBottomNav">wwdablu/LottieBottomNav</a></p><p>You can follow this story and the code along to get an understanding of it. For your reference, the readme file contains a GIF and also inside the demo folder the video is present which you can play and watch.</p><p><strong>Gradle please!</strong></p><p>First and foremost, we need the engine which would drive this animated vector drawables, which is Lottie itself. In gradle, you can specify:</p><pre>implementation &#39;com.airbnb.android:lottie:2.8.0&#39;</pre><p>Note that version 2.8.0 required androidx packages to be used. If otherwise, then you can downgrade to version 2.6.0 for example.</p><p><strong>What is a Lottie?</strong></p><p>So before we being, we need to understand the Lottie files. They are Adobe After Effects animations exported as JSON with Bodymovin. Once the JSON is obtained, it is the responsibility of the Lottie library to parse this JSON and render these animated drawables.</p><p>You can visit the following site to get many Lottie files and try them out.</p><p><a href="https://www.lottiefiles.com/">LottieFiles - Free animation files build for Lottie, Bodymovin</a></p><p><strong>LottieAnimationView — Useful methods provided</strong></p><p>The view component which is responsible to displaying the Lottie animation is LottieAnimationView. This view takes in the name of the Lottie file to be used and when displayed, it would display the animated drawable.</p><p>There are several method provided by this class (which is basically an ImageView). These can be either set from XML and/or can be called from Java/Kotlin.</p><ul><li>loop — This specifies whether the animation will play in a continuous loop.</li><li>progress — Think of it as a slider for the video. The progress (0 to 100) can be set for the animation.</li><li>playAnimation — If autoPlay is false or animation is paused, can be used to start playing the animation.</li><li>pauseAnimation — Pause the animation</li></ul><p>Animation listeners (Animator.AnimatorListener ) can be added on the LottieAnimationView to get updates about the state of the animation.</p><p><strong>Where to keep the Lottie files?</strong></p><p>The Lottie files can be kept in either assets or in the raw folder inside android res folder. The library provides separate method to specify the name of the file and the process to load them is handled by the library.</p><p><strong>Usage</strong></p><p>We will explain the usage using the LottieBottomNav library that we have created. First of all, LottieBottomNav does not extend BottomNavigation view, rather it extends LinearLayout. The reason, we cannot use Lottie on the BottomNavigationView.</p><pre>public class LottieBottomNav extends LinearLayout</pre><p>We mark the orientation as horizontal and child view’s gravity as center so that it is displayed side by side and on the center on the linear layout.</p><p>The layout uses MenuItems to display the icons and the text. The layout is defined as following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9aae1689ed87263225367dcb51ac3161/href">https://medium.com/media/9aae1689ed87263225367dcb51ac3161/href</a></iframe><p>So each of the menu items contain the LottieAndroidView (responsible for showing the Lottie) and a TextView (responsible for showing the name of the menu item).</p><p><strong>Creating Menu Items</strong></p><p>Using MenuItemBuilder, a MenuItem can be created. It provides several options to configure the menu item based on the selected and unselected state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5683aed18e6603d86ad5407d2847e9f0/href">https://medium.com/media/5683aed18e6603d86ad5407d2847e9f0/href</a></iframe><p>Now to display the text in the menu item, we need to create an instance of the FontItem. In here we can customize the text component. We can also provide a SpannableText instead of a simple string.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f5706dc018f0eda2b4e025762ffeb73/href">https://medium.com/media/8f5706dc018f0eda2b4e025762ffeb73/href</a></iframe><p>From example, in the above sample, the menu item is configured to display the text color based on the selection state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f27ef868680ceaad9770a1f1a7824142/href">https://medium.com/media/f27ef868680ceaad9770a1f1a7824142/href</a></iframe><p>The other way to do is, clone an existing menu item and then configure only the required properties. Note the tag property is not cloned or copied over.</p><p><strong>Setting up LottieBottomNav</strong></p><p>Once all the menu items to be displayed are created we need to add them to an ArrayList and then pass it by calling setMenuItemList on the bottom nav. This would create and display the menu items. Note, that the menu items are equally spaced and hence, the more the number of items, the more clumsy it would look. The maximum number sweet spot is 4.</p><pre>list = new ArrayList&lt;&gt;(4);<br>list.add(item1);<br>list.add(item2);<br>list.add(item3);<br>list.add(item4);</pre><pre>bottomNav.setCallback(this);<br>bottomNav.setMenuItemList(list);        bottomNav.setSelectedIndex(0);</pre><p><strong>Callback Listeners</strong></p><p>There are four (4) callback listeners which are provided.</p><pre>void onMenuSelected(int oldIndex, int newIndex, MenuItem menuItem);    void onAnimationStart(int index, MenuItem menuItem);<br>void onAnimationEnd(int index, MenuItem menuItem);<br>void onAnimationCancel(int index, MenuItem menuItem);</pre><p>Lottie is a very helpful library and using the animations we can enhance the usability of the application without using much text and images. Tryout the Lottie bottom navigation library and let me know about your feedback.</p><p>Updated [Nov 18, 2019]</p><p>The new version released supports font customization and SpannableString for the text to be displayed on the component. It also fixes an issue related to the loop parameter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bfbe8cd4ff7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wwdablu/lottie-using-it-in-android-5bfbe8cd4ff7">Lottie — Using it in Android</a> was originally published in <a href="https://medium.com/wwdablu">wwdablu</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sceneform — ARCore withJava (Introduction)]]></title>
            <link>https://medium.com/wwdablu/sceneform-arcore-withjava-introduction-aea4ae04d9e4?source=rss-834c31fed971------2</link>
            <guid isPermaLink="false">https://medium.com/p/aea4ae04d9e4</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[arcore]]></category>
            <dc:creator><![CDATA[Soumya Kanti Kar]]></dc:creator>
            <pubDate>Tue, 20 Nov 2018 23:26:41 GMT</pubDate>
            <atom:updated>2018-11-21T00:19:41.138Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sceneform — Introduction to AR</h3><p>Recently, I tried ARCore using Unity and really loved it. But being an Android developer, it seemed restrictive. I wanted to add it more UI components to interact with ARCore and make it more wholesome. Enter Sceneform.</p><p><a href="https://medium.com/wwdablu/arcore-with-unity-beginner-on-android-9a3da343d1ac">ARCore with Unity — Beginner on Android</a></p><p>Sceneform allows you to access ARCore using Java and by extension use Android component in conjunction with it. For example, show a model, tap on a button to play a sound.</p><p>So let us being. To learn, we will implement an application along the way. This would allow us to learn it properly and hopefully answer queries. Also note that we need to set the minimum API version as 24.</p><p>First, we need to add Sceneform to gradle. As of writing this post, the recent available version was 1.5.1.</p><pre>implementation &#39;com.google.ar.sceneform.ux:sceneform-ux:1.5.1&#39;</pre><p>We will also add compile options for Java 8 support.</p><pre>compileOptions {<br>    sourceCompatibility JavaVersion.<em>VERSION_1_8<br>    </em>targetCompatibility JavaVersion.<em>VERSION_1_8<br></em>}</pre><p>Next we need to add the permissions for Camera and also specify that for this application the device needs to support AR functionality. So we make the following changes in AndroidManifest.xml</p><pre>&lt;uses-permission android:name=&quot;android.permission.CAMERA&quot; /&gt;<br>&lt;uses-feature android:name=&quot;android.hardware.camera.ar&quot; android:required=&quot;true&quot; /&gt;</pre><p>Inside application definition we need to add the meta data information in manifest too.</p><pre>&lt;meta-data android:name=&quot;com.google.ar.core&quot; android:value=&quot;required&quot; /&gt;</pre><p>Now we need some 3D models which we can render. Now bear in mind that the models are required to be light (low polygon count) for faster rendering. Once such website from wherein you can get 3D models is:</p><p><a href="https://poly.google.com/">Poly</a></p><p>From here you can download OBJ or GLTX models which we will use in our application development.</p><p>For the purpose of development, we can use the model of Pluto.</p><p><a href="https://poly.google.com/view/cYOLkkEcJG3">Pluto</a></p><p>Click on the download button and it should download a zip file which contains the model (OBJ), material (MTL)and texture (JPG). It is not mandatory to know what are all these, but knowing a bit about them will be interesting. The OBJ can be though of as a wireframe model. It contains all the polygon data which creates the model. The MTL contains the material definitions like colors for example which will be applied on the model. It also contains information about textures to be used. Finally, textures are the potion of images which will be defined in the material file and applied to the model. You can think MTL as the map file between them.</p><p>Next, we need a tool which would create a structural information from these models and other files. For this, we will use a plugin called <strong>Google Sceneform Tools</strong>. This plugin is currently in Beta phase, but stable for development purpose. Download and install the plugin from Android Studio.</p><p>Lets start by creating an Android project. Nothing special here, just the same steps that we follow. Before we begin writing any code, one very important change that we need to do is, instead of extending from Fragment, we need to extend from ArFragment.</p><pre>public class ArPuppyFragment extends ArFragment</pre><p>This simple line does all the heavy lifting work for us. It provides us with the view on which we can continue with our development. In the layout file, we can simply use the fragment as</p><pre>&lt;fragment<br>    android:id=&quot;@+id/sceneform_fragment&quot;<br>    android:name=&quot;com.soumya.arcore.ArPuppyFragment&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:layout_alignParentTop=&quot;true&quot;<br>    /&gt;</pre><p>This looks good till here. Let us run the application and see what happens. We will observe that we are required to provide access to Camera and hence the permission dialog is displayed. Once approved, the camera is launched. You will be displayed a tutorial screen on how to detect planes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*e50Q9jSd9i9pIhRJTPfKhg.png" /><figcaption>Hand tutorial screen (can be hidden)</figcaption></figure><p>Try moving the left and right on horizontal surface and see what happens? White dots will be coming up. Congratulations!!! You have detected a plane.</p><pre><strong>Dev Note</strong>:<br>If you want to remove the tutorial screen then you can provide the following lines of codes.</pre><pre>arFragment.getPlaneDiscoveryController().hide();<br>arFragment.getPlaneDiscoveryController().setInstructionView(null);</pre><p>So before we continue, we need to understand what is plane. In real world, if we need to place an object, say for example your phone, you need to put it on a plane, for example the table. Similarly to put a virtual model into the real world, we need a plane. Once a plane is detected, we can add the models to that particular plane.</p><p>Models added to the plane will be anchored to it. Anchors are similar to ship’s anchor. They are used to define the position compared to the real world where the virtual object is being displayed.</p><p>Now with the knowledge of the basic understanding, first, we need to add the 3D model. For this, create a folder named <strong>sampledata</strong> inside the app level folder.</p><p>Once the folder is created, you can create a subfolder inside it and call it <strong>pluto</strong>. Inside this folder, we need to copy the OBJ, MTL and texture files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*X1QH0RvB8VKpeWkSKbKKsA.png" /></figure><p>Now, we need to generate the sceneform assets. For this we will be taking the help of the plugin we had downloaded earlier. For this, right-click on the OBJ file and select <strong>Import Sceneform Asset</strong>. It would create two new files with the extension <strong>sfa</strong> and <strong>sfb</strong>. These two files will be used to render the model.</p><p>If you click on the SFB file inside the assets folder, you will be shown a preview of the model which has been imported.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*fPauL_tPK6GbS16TPStPTA.png" /><figcaption>Till will take some time to generate the model files once you click finish.</figcaption></figure><p>Perfect! Now we need to drop the model once a plane is detected. Hence, the first step is plane detection. From the fragment we need access to <strong>Scene</strong>. This object contains all the nodes and its information. Node contain the renderable (3D model) and positional data. It is a graph.</p><pre>puppyFragment = (ArPuppyFragment) getSupportFragmentManager()<br>.findFragmentById(R.id.<em>sceneform_fragment</em>);</pre><pre>puppyFragment.getArSceneView().getScene()<br>.addOnUpdateListener(updateListener);</pre><p>Here is the listener implementation:</p><pre>private Scene.OnUpdateListener updateListener = frameTime -&gt; {<br><br>    Frame frame = puppyFragment.getArSceneView().getArFrame();<br>    if(frame == null) {<br>        return;<br>    }<br><br>    for(Plane plane : frame.getUpdatedTrackables(Plane.class)) {<br>        addObjectModel(Uri.<em>parse</em>(&quot;pluto.sfb&quot;));<br>        break;<br>    }<br>};</pre><p>onUpdate will be called called whenever the content of the scene is being updated. In such an instance, get can get all the detected planes corresponding to the frame. A frame can have multiple planes. We can iterate through all the planes and based on the plane which we need, we can work on it. For our case, let us consider that we add the model as soon as we detect a plane.</p><pre>private void addObjectModel(Uri object) {<br>    Frame frame = arFragment.getArSceneView().getArFrame();<br>    Point center = getScreenCenter(arFragment);<br><br>    puppyFragment.getArSceneView().getScene()<br>            .removeOnUpdateListener(updateListener);<br><br>    if(frame != null) {<br>        List&lt;HitResult&gt; result = frame.hitTest(center.x, center.y);<br>        for(HitResult hit : result) {<br>            Trackable trackable = hit.getTrackable();<br>            if (trackable instanceof Plane &amp;&amp; ((Plane) trackable).isPoseInPolygon(hit.getHitPose())) {<br>                placeObject(arFragment, hit.createAnchor(), object);<br>                break;<br>            }<br>        }<br>    }<br>}</pre><p>The way to get the center of the screen is:</p><pre>private Point getScreenCenter() {<br><br>    if(puppyFragment == null || puppyFragment.getView() == null) {<br>        return new android.graphics.Point(0,0);<br>    }<br><br>    int w = puppyFragment.getView().getWidth()/2;<br>    int h = puppyFragment.getView().getHeight()/2;<br>    return new android.graphics.Point(w, h);<br>}</pre><p>The above method is going to add the model to the plane. To this, we need to pass the ArFragment and the Uri of the model, for example:</p><pre>Uri.<em>parse</em>(&quot;Pluto.sfb&quot;)</pre><p>Before placing the object, we need to perform a hit test. Think of this process as sending laser lights to the plane on a coordinate with respect to the device screen and figuring out as to whether a viable plane is present on which the model can be rendered. This would give us a proper HitResult which can be used to create an anchor.</p><pre>private void placeObject(Anchor anchor, Uri object) {<br>    ModelRenderable.<em>builder</em>()<br>        .setSource(puppyFragment.getContext(), object)<br>        .build()<br>        .thenAccept(modelRenderable -&gt; addNodeToScene(anchor, modelRenderable, object))<br>        .exceptionally(throwable -&gt; null);<br>}</pre><p>This method will load the 3D model and a renderable form which will be placed in the defined anchor. Anchors in ARCore does that same thing it does to a ship. It fixes the object from drifting away. Hence in AR too, once the object has been placed into the real world, it will stay in that location until and unless it has been moved by user or programatically.</p><p>ModelRenderable provides an async implementation for the load process. Once the loading has been done we can proceed to add the node to the scene.</p><pre>private void addNodeToScene(Anchor createAnchor, ModelRenderable renderable, Uri object) {<br>    AnchorNode anchorNode = new AnchorNode(createAnchor);<br>    TransformableNode transformableNode = new TransformableNode(puppyFragment.getTransformationSystem());<br>    transformableNode.setName(object.toString());<br>    transformableNode.setRenderable(renderable);<br>    transformableNode.setParent(anchorNode);<br><br>    puppyFragment.getArSceneView().getScene().addChild(anchorNode);<br><br>    transformableNode.setOnTapListener((hitTestResult, motionEvent) -&gt; {<br>        //Perform callback action, like bark<br>    });<br>    transformableNode.select();<br>}</pre><p>Finally we come to the node wherein the model which has been loaded will be added to the scene. Like we have mentioned earlier that we need nodes to connect and form the graph, we will create an anchor node form the anchor. Next we create another node which would contain the renderable information. In this instance we are using TransformableNode. This transformable node would contain the renderable and the anchor node. Once complete, we just need to add it to the scene.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*FDKUZTOdyTWfJGmUfzLNPw.png" /><figcaption>Pluto on my desk</figcaption></figure><p>There we have it. Pluto’s 3D model has been added to the real world.</p><p>So now that we have Pluto being displayed, let us go ahead, add the button and when you tap on the button make him bark. his purpose of this task is to show the easy integration with other Android components.</p><p>This is how the layout would look like.</p><pre>&lt;RelativeLayout<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    tools:context=&quot;.MainActivity&quot;&gt;<br><br>    &lt;fragment<br>        android:id=&quot;@+id/sceneform_fragment&quot;<br>        android:name=&quot;com.soumya.arcore.ArPuppyFragment&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;match_parent&quot;<br>        android:layout_alignParentTop=&quot;true&quot;<br>        /&gt;<br><br>    &lt;Button<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:id=&quot;@+id/bark_pluto&quot;<br>        android:text=&quot;Bark&quot;<br>        android:textSize=&quot;16sp&quot;<br>        android:layout_alignParentBottom=&quot;true&quot;<br>        android:layout_margin=&quot;8dp&quot;<br>        android:visibility=&quot;gone&quot;<br>        /&gt;<br><br>&lt;/RelativeLayout&gt;</pre><p>Now, inside onUpdate, once the plane is detected, we can set the visibility of the button to true and then on click of the button we can perform the barking or any other operation that we want to perform.</p><pre><strong>Dev Note</strong>:<br>puppyFragment.getArSceneView().getScene()<br>            .removeOnUpdateListener(updateListener);</pre><pre>The listener is being removed inside the addModel method as because if not done then it would add multiple models and burden the system with each scene update. Hence using this we want to make only one model to be drawn for our application.</pre><p>This is just a small portion of the implementation using ARCore with Sceneform. The libraries itself are evolving with each release. For example, skeletal animation for the models are not yet supported, but there is an open request for it being implemented.</p><p><a href="https://github.com/google-ar/sceneform-android-sdk">google-ar/sceneform-android-sdk</a></p><p>Hope this post has been able to provide (even if a small) head start into the development using Sceneform. Do let me know your thoughts and feedback. Till then augment the reality to the core.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aea4ae04d9e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wwdablu/sceneform-arcore-withjava-introduction-aea4ae04d9e4">Sceneform — ARCore withJava (Introduction)</a> was originally published in <a href="https://medium.com/wwdablu">wwdablu</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Assistant — An Introduction]]></title>
            <link>https://medium.com/wwdablu/google-assistant-an-introduction-19943f4e4e57?source=rss-834c31fed971------2</link>
            <guid isPermaLink="false">https://medium.com/p/19943f4e4e57</guid>
            <category><![CDATA[google-assistant]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Soumya Kanti Kar]]></dc:creator>
            <pubDate>Wed, 25 Jul 2018 05:24:40 GMT</pubDate>
            <atom:updated>2018-07-25T05:24:40.752Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OXQ7hg5TC2LSiyOybfvxvg.jpeg" /></figure><p>After buying my Pixel 2 device, I got a Google Home as a free gift as part of the pre-order offer. Once I had it, I was quite impressed. After using it for few days, it became a part of the daily life, news, weather, songs, jokes and trying out queries to see what the lady responds.</p><p>In all these, I wondered how about creating my own action for Google Assistant. Having a very basic knowledge on working with Amazon Alexa, I sat down to create a very simple workflow and learn it.</p><p>At first, let us understand few terminologies.</p><p><strong>Action</strong><br>An Action is an entry point into an interaction that you build for the Assistant. Users can request your Action by typing or speaking to the Assistant.</p><p><strong>Intent</strong><br>An underlying goal or task the user wants to do; for example, ordering coffee or finding a piece of music. In Actions on Google, this is represented as a unique identifier and the corresponding user utterances that can trigger the intent.</p><p><strong>Fulfilment</strong><br>A service, app, feed, conversation, or other logic that handles an intent and carries out the corresponding Action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tBX3cMv2Fx3QOmAqOgdnPw.png" /><figcaption>Google Code Labs — Part 1</figcaption></figure><p>First of, we need to create a project, as usual. For this, let us go to <a href="https://console.actions.google.com/u/0/">console</a>. Once inside, create a project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hnbbJrXyWjcS1r6X6t-ivA.png" /><figcaption>Provide me the name of the project</figcaption></figure><p>Once the project has been created. We need to build actions for it. On the left navigation you should see the option and it might look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w5ES-42-4AjYzhdySkhsYg.png" /><figcaption>Empty actions as of yet</figcaption></figure><p>For this example we are going to build a custom action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WWRDfOzRq0RABTPxoZG2hA.png" /><figcaption>Select the custom intent</figcaption></figure><p>This would redirect you to the DialogFlow console. This is basically a NLU or <em>Natural Language Understanding</em> handler. That means, it allows us to interpret the phrases provided by the user and extract the applicable information.</p><p>As per Google’s definition:</p><ul><li>Dialogflow: A web-based service provided by Google that uses an agent to process user input. This service allows you to integrate conversational apps with the Assistant, as well as with other conversation platforms.</li><li>NLU: Acronym for “Natural Language Understanding”. This refers to the capability of software to understand and parse user input.</li></ul><p>The image below should provide a better understanding of the components in action for the process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vSj2FzWCr9C0rY1x7FfS-g.png" /><figcaption>Google Code Lab — Part 1</figcaption></figure><p>In the DialogFlow console you should see something similar to this. It should specify your project name. If yes, click on the create button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o-fDmVmmc8AkDCw-7n9KHQ.png" /><figcaption>Dialog Flow</figcaption></figure><p>Once the agent has been successfully created, we will now be creating intents. There should already be a default welcome and fallback intent already created for our usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-jMCEFkSCF_zbrGWWFAxYw.png" /><figcaption>Default intents</figcaption></figure><p>Click on Default Welcome Intent. In the responses tab, remove all the default responses and once done, we will create a new response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cag5_m5bswSeKChDfuj4HA.png" /><figcaption>Empty response</figcaption></figure><p>Once we add a text response, click on the save button. Now, let us try to integrate. On the left nav, there should be an option called Integrations. On Google Assistant click on the integration settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3NEJTN3mhSEvjknl1FFEsQ.png" /><figcaption>Google Assistant Integration Settings</figcaption></figure><p>It should display the following settings dialog. Click on the Test button and click on the continue button on the next dialog. Once we have the simulator running it should be something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sBFnjseFCFYkg_K_3kzGHg.png" /><figcaption>Simulator running our test app</figcaption></figure><p>In here if we invoke the intent or say “Talk to my test app” using the microphone, then we will be greeted with the welcome string that we have provided.</p><p>Great! We have been able to initiate the conversation, but then again this is not a conversation. Hence, the next step for us would be to initiate the conversation mode.</p><p>Hence let us begin and create an intent. For doing this, you need to visit the dashboard console.</p><p>Once an intent has been created. We need to provide the training phrases. The option should look something similar to this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MVTg1X57eIZBizwYscABxw.png" /><figcaption>Input for training phrases</figcaption></figure><p>Next we need to add the action and parameters. In this case, the NLU performs the magic and provides us the data what we are interested in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BKoeWsvXyfzsZMXAEKtU8Q.png" /><figcaption>Creating a parameter</figcaption></figure><p>Now, we might need to perform some action on the backend. For this purpose, we are going to use the WebHook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EZeb9QIoFx1qJIFcX5LLPQ.png" /><figcaption>Enable WebHook for this intent</figcaption></figure><p>Now, let us implement the WebHook. On the left navigation there should be an option for it called Fulfillment. Enable the inline editor for the purpose of this usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Ed_54CraI6fSSHKQekhjQ.png" /><figcaption>Enable inline editor</figcaption></figure><p>Once we add in the respective code, we can click on the deploy button. This would ensure that the JavaScript code is now in the cloud and can be invoked by the action to execute it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jMB6qXTZ9EFgxiyuQkO0DQ.png" /><figcaption>index.js — Our JavaScript code which will be executed (WebHook)</figcaption></figure><p>The above portion of the code would be executed if the provided intent is found. In here, the input parameters are to the conversation object and the input provided by the user. This is same as the one we provided in the intent, that is $nextStep. So, as an example, when the user says “done” verbally, the value contained in the parameter nextStep will be string done.</p><p>In the Actions control panel, the action can be released to production so that it can be made available to others to try it. You can also test it on your own device if the email account on which the action is being developed is connected to a device. For example, here is the screenshot from my device wherein I am running the action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*TPAv9ZjpA00y7auTk2IZxA.png" /><figcaption>Executing the action on Pixel 2 device</figcaption></figure><p>This is just an introduction to get a hands-on on the process, just to get a taste of the process. The next step is to create a more interactive action and see how it behaves. Till then, will wait for the action to be approved. 🤞</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19943f4e4e57" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wwdablu/google-assistant-an-introduction-19943f4e4e57">Google Assistant — An Introduction</a> was originally published in <a href="https://medium.com/wwdablu">wwdablu</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ARCore with Unity — Beginner on Android]]></title>
            <link>https://medium.com/wwdablu/arcore-with-unity-beginner-on-android-9a3da343d1ac?source=rss-834c31fed971------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a3da343d1ac</guid>
            <category><![CDATA[virtual-reality]]></category>
            <category><![CDATA[arcore]]></category>
            <dc:creator><![CDATA[Soumya Kanti Kar]]></dc:creator>
            <pubDate>Sun, 13 May 2018 23:12:40 GMT</pubDate>
            <atom:updated>2018-05-13T23:12:40.344Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zV3xHLfVHls6rOim_fqBbg.png" /><figcaption>Face to face with Diablo through ARCore</figcaption></figure><p>With the improvements in computer vision and superior hardware advancements, AR and VR are bound to become part of our daily life. Also Google brought out ARCore 1.2.0. With all of these, I had to try out and have a hands on experience.</p><p>For the tutorial, we need some basic knowledge on using Unity. For me, with no formal training on Unity, my first task was to find some online tutorials which can introduce me to it and once I am familiarised with it, then I can look out for some more advanced sessions. As for ARCore, the content seems very scarce. There are courses on various training websites, but I am not sure on how good or otherwise they are. Also basic knowledge of C# is required.</p><p>Also note, the information provided below are based on the my own personal understanding, knowledge and experience. I too am learning it. I would be glad if you share your thoughts and knowledge too. You would also require an ARCore supported device. For me, I am currently using Pixel 2 device.</p><p>ARCore has three main parts which are used for rendering virtual content on the real world using the display medium (like Camera)</p><ul><li><strong>Understanding the environment</strong> — Ability to recognise the horizontal surface on which the real world. This surface will be used to anchor the virtual objects.</li><li><strong>Motion Tracking</strong> — Used for tracking the virtual objects on the real world. It provides the ability to anchor virtual objects on different places.</li><li><strong>Lighting Estimation</strong> — Provides the logic for taking the lighting information from the real world and applying it on the virtual object.</li></ul><p>Let us start with developing our first application using Unity and ARCore for Android. We are going to disable a virtual object on real world.</p><p>Checklist before we can continue. You can continue even if you do not meet all the requirements, but you will not be able to build and deploy.</p><ul><li>Unity 2018.1.0f2</li><li>Android SDK 7.0 and higher</li><li>Google ARCore SDK for Unity</li><li>Supported hardware for deployment (I am using Pixel 2)</li></ul><p><a href="https://github.com/google-ar/arcore-unity-sdk/releases/">google-ar/arcore-unity-sdk</a></p><p>Create a new application in Unity and let us name it as ARCoreWorld.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qJhIIjpCMMxsfkZKRtzY2g.png" /></figure><p>Once done, we need to import the Unity file which we had downloaded. To import, Assets → Import Package → Custom Package. Select the file and click import to start the process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*clgvSdVKqax_u3xHNDvjBg.png" /><figcaption>ARCore Unity SDK (At the time of writing this 1.2.0 was latest)</figcaption></figure><p>It should then display the items that are being imported. For this case, we are going to import everything.</p><p>Once imported delete, main camera and directional light component. Then add the prefab (1) ARCore Device and (2) Environmental Light.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NcTm0_KajwKdskQtHe8Mgg.png" /><figcaption>All Prefabs can be found under Favourites → All Prefabs on Project container (bottom left)</figcaption></figure><p>In this state, the application is buildable, but to make it build for Android, we need to switch the platform. To access the build settings you can do it from File → Build Settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ywR9p3jxH0bJ4euJSSKGGQ.png" /><figcaption>Select Android and then click on Switch Platform</figcaption></figure><p>Once it is done, click on Player Settings and in here we are going to make the following changes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*TGelgI4OZu2X5OueExmEHA.png" /></figure><p>In here we are going to provide a valid package name. Set the Minimum API level to Android API 24 and that target as the highest installed. Also note to disable multithreaded rendering. In the XR Settings, we are going to enable ARCore Support.</p><p>At this point, the skeleton code is ready but running this application now would just display the real view through the camera.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*oJVL6xYXiEJ6V7BsDYaAog.png" /><figcaption>Nothing surprising in here</figcaption></figure><p><strong>Point Cloud</strong></p><p>Point clouds is a container which contains set of 3D data point information about the real world. They are used to deduce information about the real world and the composition of the frame to augment it with virtual object.</p><p>For this we need to create a material. Materials are objects which allows us to provide texture or color information to a 3D model.</p><p>Create a material named PointMaterial and assign the shader type as ARCore → PointCloud. I changed the size to 15 and the color to red.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*fNjbXqPGz2yUwMVpMTU6Dg.png" /></figure><p>Now, once the material is created we need to create an object in which we can use this material. For this purpose, we will create a cube. Once the cube is created we are going to use the material on the cube. And finally, we need to add a component called, Pointcloud Visualizer.</p><p>Building the application at the current state would look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*1baK31pgFIgLmdP7A1flFQ.png" /><figcaption>Point Cloud detection on the keyboard</figcaption></figure><p>We now have the field ready. Now we are going to place our virtual object into the real world. The object is Diablo. You can get the model from here. This has been created by another developer. I am using it for the purpose of learning.</p><p><a href="http://www.cadnav.com/3d-models/model-22720.html">Prime Evil Diablo 3d model 3ds max,Object files free download - modeling 22720 on CadNav</a></p><p>Let us import the model into Unity. Create a folder named Diablo and drag and drop the .OBJ file into it. Once the model has been imported you will notice that it is just the wireframe of the model. There is no texture. Not to worry. The developer of the model has also included the required texture too, but that is in DDS format. We need to convert from DDS to TGA so that we can import it to Unity. You can use any of the online tools to perform the conversion. Once done, drag and drop the TGA file into Unity.</p><p>To use the TGA file and use it as a texture we need to create a material out of it. For this create a new material and use the shader as Unlit/Texture. Then use the TGA file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*e06hy06KMM3ALnsEmSqQRg.png" /></figure><p>Now drag the new material into the Diablo model and see that it changes from the greyscale model to the one that we want to see.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*PiNiXi-XHR94swKZ44CHaA.png" /><figcaption>Diablo model once the material is applied</figcaption></figure><p>I reduced the scale of the model as otherwise it was very big. You can reduce the scale by selecting the model and reduce the scale factor from 1 to 0.15 or as you desire. Once done, create a prefab from the Diablo model which we will be using on the renderer later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*xSpZyquT7MG9dGL2Wc9Otw.png" /></figure><p>Now we need view the plane on which the virtual object would be draw. For this we can use the Plane Generator and Plane Visualiser component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*2stAWERD6TQCUIcLCtwH1g.png" /><figcaption>Plane generator (interconnected triangles) with point cloud.</figcaption></figure><p>Going forward we will reduce the size of the point cloud cube to 5 units.</p><p>Now lets get into some coding. We have the plane, the model with the applied texture. Now we need to place virtual object of Diablo on real world.</p><p>Create an empty object and call it DiabloRenderer. Now add a new C# script attached to it. The update method should look something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bdb18a107edb44da9be2211734c66493/href">https://medium.com/media/bdb18a107edb44da9be2211734c66493/href</a></iframe><p>First, we need to expose three variables which we then need to link.</p><ul><li>FirstPersonCamera — This is the camera that can be found on ARCore Device. This will allows us to view the virtual object.</li><li>DetectedPlanePreFab — This will be used for the plane detection on which the virtual object is to be rendered.</li><li>DiabloGameObject — This is the prefab of the Diablo model.</li></ul><pre>if (Input.touchCount &lt; 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)</pre><p>This method will check if we have clicked on the screen. If not, then there is nothing to be drawn.</p><pre>if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))</pre><p>Once we touch on the screen, the above will take the input from the screen coordinate on the touch and then case it to the position where the virtual object needs be placed on the real world.</p><pre>var diabloGameObj = Instantiate(DiabloGameObject, hit.Pose.position, hit.Pose.rotation);</pre><pre>diabloGameObj.transform.Rotate(0, k_ModelRotation, 0, Space.Self);<br>var anchor = hit.Trackable.CreateAnchor(hit.Pose);<br>diabloGameObj.transform.parent = anchor.transform;</pre><p>If the hit is good and is favourable for rendering then first an instance of the game object, for this case the diablo model will be created. On real world it will be placed on the location defined by hit.Pose.position. Next, to affix the model in a place on the real world, even if we try to move around the model, we need to ensure that the virtual object is anchored to the Pose in which it was created. Hence, we create an Anchor and assigned it to the parent of the game object.</p><p>Alright, so we have made many changes. Let us now see how our application looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*Vzo1O9swXDdt-r8e1BQ_SA.png" /><figcaption>Reduced the scale to 0.05 for the purpose of the screenshot</figcaption></figure><p>The virtual object can be viewed 360 degree. The below video provides all the details.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQ8UFLgdlRCw%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQ8UFLgdlRCw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FQ8UFLgdlRCw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d680b5affa4c9ed998d2e1727284354f/href">https://medium.com/media/d680b5affa4c9ed998d2e1727284354f/href</a></iframe><p>We have used the Google ARCore example for our understanding. I will continue to work on this and will try to make some more changes to improve on this application. Will try to create a next part to this. Will try to improve more on this and try to go to the next level.</p><p>Hope I have been able provide the information and go through some of the points. Do let me know if you have any comment and any pointers on which I can look into and learn more on this.</p><p><a href="https://github.com/wwdablu/ARCoreWorld">wwdablu/ARCoreWorld</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a3da343d1ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wwdablu/arcore-with-unity-beginner-on-android-9a3da343d1ac">ARCore with Unity — Beginner on Android</a> was originally published in <a href="https://medium.com/wwdablu">wwdablu</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Architecture Components — ViewModel and LiveData]]></title>
            <link>https://medium.com/wwdablu/android-architecture-components-viewmodel-and-livedata-97acc8a07c72?source=rss-834c31fed971------2</link>
            <guid isPermaLink="false">https://medium.com/p/97acc8a07c72</guid>
            <category><![CDATA[android-architecture]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Soumya Kanti Kar]]></dc:creator>
            <pubDate>Tue, 08 May 2018 07:10:05 GMT</pubDate>
            <atom:updated>2019-08-27T02:06:34.496Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I planned to update an Android application that I wrote long back. While going through the code, I found many places wherein there were scopes of improvement. There were many portions of the code which was working, but something did not feel good.</p><p>While planning to improve the code, I thought why not try out the <a href="https://developer.android.com/topic/libraries/architecture/">Android Architecture Components</a>. I wanted to play around with it and learn on how we can integrate it with an existing application and measure the learning curve (which will be different from person to person but I hope to justify it)</p><p>First of, this discussion covers LiveData and ViewModel. Room is not in the scope of this discussion. These are just my through process and thinking on the implementation front. It may vary with other developers and I welcome them to share their ideas.</p><p><strong>Gradle</strong></p><p>To use the Android Architecture Component, LiveData and ViewModel we need to specify this in the gradle.</p><pre>// ViewModel and LiveData<br>implementation &quot;android.arch.lifecycle:extensions:1.1.1&quot;</pre><p><strong>ViewModel</strong></p><p>ViewModels provide the data to be displayed by the UI from the model, in a lifecycle aware manner. It can survive configuration changes. Bind it with the view XML and that reduces more of the boiler code to display data on UI. To create a ViewModel, we need to extend the ViewModel or the AndroidViewModel class.</p><p>The difference between the ViewModel and the AndroidViewModel class is that the later one provides you with an application context, which you need to provide when you create a view model of type AndroidViewModel. If there is no requirement of context information on the ViewModel being created then we should always use ViewModel.</p><pre>public class SimpleViewModel extends ViewModel {<br>    ...<br>}</pre><p>Now incase you need the AndroidViewModel</p><pre>public class ViewModelWithContext extends AndroidViewModel {<br>    public ViewModelWithContext(Application application) {<br>        super(application);<br>    }<br>}</pre><p>One very important thing to keep in mind is that we should not store any reference to views on the ViewModel. Doing so will lead to memory leak and we all know how scary it is.</p><p>For devs who are yet to face fixing memory leak scenario, its like Conjuring demon nun with ability to rotate her head like exorcist and crazy like Pennywise clown. You need to tackle such a beast.</p><p><strong>Live Data</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*--8G3qmQDUHu294Q4Ov9jg.gif" /></figure><p>Live data are basically observables. They are… alive! Meaning, any changes that occur to the data will trigger the attached active observers. In here we have used the MutableLiveData&lt;T&gt; implementation of LiveData.</p><p>MutableLiveData&lt;T&gt; provides us with a LiveData which is mutable in characteristic. It provides get and set/post methods for the data it holds. setValue method can be called from the main thread and postValue method can be called from the background thread.</p><p>Let us see an example as to how we can declare a LiveData:</p><pre>private MutableLiveData&lt;UserInfo&gt; liveUserInfoData;</pre><p><strong>Using ViewModels</strong></p><p>So, now that we have some basic concept ready. Let us see how we can use ViewModel from activity or fragment.</p><pre>ViewModel vm = ViewModelProviders.<em>of</em>(this).get(ViewModel.class);</pre><p>In this case, this refers to as the fragment or the activity. If we read, it literally means “provide me the view model of &lt;this activity or fragment&gt; which is of type &lt;view model class”. Hence, the view model of this parent will always return the same instance for the same instance of the parent.</p><p>Now if the activity has an instance of a ViewModel which stores an information, then even if orientation change occurs the fragment or activity will return the same view model hence, the data still remains.</p><p><strong>Use Case Scenario</strong></p><p>Now let us see how we can combine both ViewModel and MutableLiveData to present an UI. The use case scenario is that we are going to simulate a web service call to fetch the user information and once retrieved we will display it in the UI.</p><p>First, let us create the ViewModel which will have the mock web service call to create an instance of the UserInfo object.</p><pre>public class UserViewModel extends ViewModel {</pre><pre>    private MutableLiveData&lt;UserInfo&gt; liveUserInfoData;<br>    private int flag = 0;</pre><pre>    public UserViewModel() {<br>        liveUserInfoData = new MutableLiveData&lt;&gt;();</pre><pre>        Observable.<em>interval</em>(5000, 1000, TimeUnit.<em>MILLISECONDS</em>)<br>            .takeWhile(new Func1&lt;Long, Boolean&gt;() {<br>                @Override<br>                public Boolean call(Long aLong) {<br>                    return flag == 0;<br>                }<br>            })<br>            .subscribeOn(Schedulers.<em>computation</em>())<br>            .observeOn(AndroidSchedulers.<em>mainThread</em>())<br>            .subscribe(new Action1&lt;Long&gt;() {<br>                @Override<br>                public void call(Long aLong) {</pre><pre>                    UserInfo userInfo = new UserInfo();<br>                    userInfo.setName(&quot;John Doe&quot;);<br>                    userInfo.setLocation(&quot;Caldeum Bazaar&quot;);<br>                    liveUserInfoData.setValue(userInfo);<br>                    flag = 1;<br>                }<br>            });<br>    }</pre><pre>    public MutableLiveData&lt;UserInfo&gt; getLiveUserInfoData() {<br>        return liveUserInfoData;<br>    }<br>}</pre><p>The above code will create UserInfo object after the defined delay and then set the value (we have observeOn main thread). Now, as soon as the setValue is called it will notify all its observers that there is a change on the content of the live data and the respective observers need to take action.</p><p>So how do we use this ViewModel from the activity.</p><pre>@Override<br>protected void onCreate(Bundle savedInstanceState) {<br>    super.onCreate(savedInstanceState);</pre><pre>    mBinder = DataBindingUtil.<em>setContentView</em>(this, R.layout.<em>a_main</em>);<br>    mBinder.setLifecycleOwner(this);</pre><pre>    userViewModel = ViewModelProviders.<em>of</em>(this)<br>                        .get(UserViewModel.class);<br>    mBinder.setViewModel(userViewModel);<br>}</pre><p>We are already familiar with the call to ViewModelProviders. Using it we can get the instance of the ViewModel that we need to use. What is up with the setLifeCycleOwner call?</p><p>We want to use the LiveData for the data binding purpose and to propagate any notification to the observers about the content change, we need to call this method. This method will facilitate the bridge between the view model provide, in this case the activity and with the live data. If this call is not done, any changes in the LiveData will not be reflected on the UI.</p><p>Alright. How about the XML?</p><pre>&lt;layout&gt;</pre><pre>    &lt;data&gt;<br>        &lt;variable<br>            name=&quot;viewModel&quot;<br>            type=&quot;com.wwdablu.soumya.androidarch.UserViewModel&quot;/&gt;<br>    &lt;/data&gt;</pre><pre>    &lt;LinearLayout <br>        xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>        xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;match_parent&quot;<br>        android:orientation=&quot;vertical&quot;<br>        tools:context=&quot;.MainActivity&quot;&gt;</pre><pre>        &lt;TextView<br>            android:layout_width=&quot;wrap_content&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:text=&quot;@{viewModel.liveUserInfoData.userName}&quot;<br>            android:id=&quot;@+id/tv_counter&quot; /&gt;</pre><pre>    &lt;/LinearLayout&gt;</pre><pre>&lt;/layout&gt;</pre><p>We are binding the view model with the UI. As soon as the setValue call is done on the ViewModel, the content of the TextView will be updated.</p><p><strong>Transformations</strong></p><p>There is another interesting part of LiveData and that is transformations. We can transform the data before being posted on the LiveData. For example:</p><pre>LiveData&lt;String&gt; helloUser = Transformations.<em>map</em>(liveUserInfoData, new Function&lt;UserInfo, String&gt;() {<br>    @Override<br>    public String apply(UserInfo input) {<br>        return &quot;Namaskar, &quot; + input.getUserName();<br>    }<br>});</pre><p>So what would happen is as soon as the liveUserInfoData, i.e the LiveData is populated, the map method would be triggered and it would result in creating the required new output stored on LiveData helloUser.</p><p><strong>onSaveInstanceState()</strong></p><p>Does this mean we are done with this method and everything can be handled by the ViewModels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*VZ9PwTZhs7lzdLFwbYX0Wg.gif" /></figure><p>Well, we will still require the onSaveInstanceState(). The reason being that ViewModels will be retained across configuration changes but not when the application is closed an relaunched. onSaveInstanceState() can survive across configuration as well as the application close scenario.</p><p>Then, why do we not use onSaveInstance() always? Well, we should be this implementation only if we need to retain information even if the application is killed. If not, then we can use ViewModel.</p><p><strong>Conclusion</strong></p><p>Being completely new to Android Architecture Component, picking up the basics was very fast. The learning curve is a bit low if you are familiar with observable pattern and had prior hands on with RxJava for example. Once you get the taste of it, there is no going back. It makes development smooth, and quick.</p><p>If you have any comment or feedback, then please do let me know. Also if you have another approaches of doing it, do share it with us.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97acc8a07c72" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wwdablu/android-architecture-components-viewmodel-and-livedata-97acc8a07c72">Android Architecture Components — ViewModel and LiveData</a> was originally published in <a href="https://medium.com/wwdablu">wwdablu</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>