<?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 Sujith Niraikulathan on Medium]]></title>
        <description><![CDATA[Stories by Sujith Niraikulathan on Medium]]></description>
        <link>https://medium.com/@sujith.niraikulathan?source=rss-8d8ec01d99d9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4MF2L67GaYnGnPoFO-5IVw.jpeg</url>
            <title>Stories by Sujith Niraikulathan on Medium</title>
            <link>https://medium.com/@sujith.niraikulathan?source=rss-8d8ec01d99d9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 23:47:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sujith.niraikulathan/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[Menu Animation Android]]></title>
            <link>https://medium.com/mindorks/menu-animation-android-2876869d5855?source=rss-8d8ec01d99d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2876869d5855</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Sujith Niraikulathan]]></dc:creator>
            <pubDate>Tue, 13 Jun 2017 02:24:20 GMT</pubDate>
            <atom:updated>2018-08-16T02:25:42.870Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone, this is Sujith. Today I am going to talk about a different kind of animation in RecyclerView.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXK4Y4Sl5zIo%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXK4Y4Sl5zIo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FXK4Y4Sl5zIo%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/1959e68a3dde205d1f4c6fbd539fc965/href">https://medium.com/media/1959e68a3dde205d1f4c6fbd539fc965/href</a></iframe><p>This video shows the animation I have made in the RecyclerView. For this, I have written my own code to load and cache images. You can use Picasso or Glide to do the same. I will tell you how it works. Then you will have a better understanding of how to write custom components and draw bitmaps and to manipulate views according to your requirements.</p><p>The first part is to create a view which allows you to scroll image inside horizontally inside the view.</p><p><strong>SliderImageView</strong></p><p>For this, you need to know how to draw a bitmap in views. It’s pretty simple than you think. Create a new class and extend it to view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dcc397c69426e4c24752e63a1949a138/href">https://medium.com/media/dcc397c69426e4c24752e63a1949a138/href</a></iframe><p>You need to override the onDraw() and onMeasure() methods for this example.</p><blockquote>OnDraw() To draw something on the view, you have to override this method to get the canvas of this view.</blockquote><blockquote>onMeasure() To get whenever the view size is measured, you will know that my this method.</blockquote><p>Now lets see how to draw a bitmap. The bitmap is nothing but the collection of raw pixels.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0b1fa05818993e22a9b86d1a3143b8d/href">https://medium.com/media/a0b1fa05818993e22a9b86d1a3143b8d/href</a></iframe><p>In this code snippet, we tried to draw a bitmap, but lets see what all it requires.</p><p>To draw a bitmap, you need a bitmap, source bounds(Rect), draw bounds(Rect) and a paint object.</p><ol><li><strong>Bitmap </strong>is whatever image file you loaded into memory.</li><li><strong>SourceBounds </strong>is just a Rect object which contains the bounds details of the image portion we are going to draw on the canvas.</li><li><strong>DrawBounds </strong>is also a Rect object which defines where you want to draw the image (In our case, it is the bounds of the entire view itself).</li><li><strong>Paint </strong>holds the style and color information about how to draw geometries, text, and bitmaps.</li></ol><blockquote><strong>Rect </strong>object will have the boundary variables which are left, right, top and bottom</blockquote><p>The drawBounds object should have left = 0, top = 0, right = viewWidth and bottom = view height. We have to keep the view square, in this case, the right and bottom will be equal.</p><p>The sourceBounds will have the bounds of the portion of the image. left = x, top = 0, bottom = view height, right = x + view height. Since the view is square, the bounds width should always have to be equal to bounds height. To do the sliding, all you have to do is change the value of x according to the fraction. But x cannot be greater that the bitmapWidth — viewWidth. If it exceeds, then the rect will go out of bounds and only rect part of the image will be drawn on screen.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FReYYOrIRZug%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DReYYOrIRZug&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FReYYOrIRZug%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/a592334c0427ba48645ea68243034e95/href">https://medium.com/media/a592334c0427ba48645ea68243034e95/href</a></iframe><p>In this video, the first image is the fully loaded image. The blue dashed rectangle represents the source bounds. The second image shows the drawn part of the image. If I change the position of the rectangle, whatever is inside the rectangle will be drawn in the second image.</p><p>Not lets apply the idea in our custom view, the class will look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe35b6a1ee16d9156a1187bced3964a7/href">https://medium.com/media/fe35b6a1ee16d9156a1187bced3964a7/href</a></iframe><p>Here we are going to use mAnimationFactor(float) variable to position the source bounds of the bitmap. All you need to find is the range of the bitmap rect sliding area to slide the rect over the bitmap. The range is the distance between 0 to (bitmap width — view width). Now multiply mAnimationFactor to the range and you will get the left of the source bounds rect. Add the source bounds left to the view width will give you the value of the source bound’s right(mAnimationFactor must be between 0–1). That’s it, sliderImageView.setAnimationFactor() will show the portion of the image according to the float value you pass.</p><p><strong>RecyclerView</strong></p><p>Lets create an XML for the items of RecyclerView.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    android:id=&quot;@+id/coloFillLayout&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;200dp&quot;<br>    android:layout_marginBottom=&quot;40dp&quot;<br>    android:layout_marginLeft=&quot;40dp&quot;<br>    android:layout_marginRight=&quot;40dp&quot;<br>    android:layout_marginTop=&quot;40dp&quot;&gt;<br><br>    &lt;android.support.v7.widget.CardView<br>        android:id=&quot;@+id/contentView&quot;<br>        android:layout_width=&quot;150dp&quot;<br>        android:layout_height=&quot;120dp&quot;<br>        android:layout_centerInParent=&quot;true&quot;<br>        app:cardElevation=&quot;15dp&quot;<br>        app:cardMaxElevation=&quot;15dp&quot;&gt;<br><br>        &lt;TextView<br>            android:id=&quot;@+id/content&quot;<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;match_parent&quot;<br>            android:background=&quot;@android:color/white&quot;<br>            android:gravity=&quot;center&quot;<br>            android:padding=&quot;20dp&quot;<br>            android:textColor=&quot;#232323&quot;<br>            android:textSize=&quot;14sp&quot; /&gt;<br><br>    &lt;/android.support.v7.widget.CardView&gt;<br><br>    &lt;com.hsalf.menuanim.widgets.SliderImageView<br>        android:id=&quot;@+id/sliderImageView&quot;<br>        android:layout_width=&quot;150dp&quot;<br>        android:layout_height=&quot;150dp&quot;<br>        android:layout_centerInParent=&quot;true&quot;<br>        app:cardElevation=&quot;15dp&quot;<br>        app:cardMaxElevation=&quot;15dp&quot; /&gt;<br><br>&lt;/RelativeLayout&gt;</pre><p>The above XML will form the layout item like this. The green color layout is just an empty view with color. Just not included in this XML to avoid confusions in the code, we are not gonna refer that view anywhere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0VqlsW_oxR1m1EKGI-QchA.jpeg" /></figure><p>I am not going to go deep into the creation of RecyclerView or its adapter. Lets just keep on learning about the animations and necessary snippets for it. I have created a viewHolder for the adapter of the recyclerView.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bed9a33758b186b9ab17b973e545127e/href">https://medium.com/media/bed9a33758b186b9ab17b973e545127e/href</a></iframe><p><strong>content </strong>is a textView which shows the details of the item, <strong>contentView</strong> is a cardView which holds the <strong>content</strong>(TextView) and <strong>imageCard </strong>is the view we created to show and slide our images.</p><p>Now lets add a method in adapter to animate views, in our case, slide views.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fa1980c865eaa3abf22b3a531bf0d58/href">https://medium.com/media/4fa1980c865eaa3abf22b3a531bf0d58/href</a></iframe><p>All the code lines have been explained in the code comments. Now, all we have to do is to pass the viewHolder object of the RecyclerView to slide the views inside the item according to the position on scrolling the RecyclerView.</p><p>Create a scroll listener and override <strong>onScrolled()</strong> method. From there you can get items visible on RecyclerView and their viewHolder objects. Take them all and pass it to the method we created above in the adapter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5bd4bcc7d7da750578c924f42c3bea8/href">https://medium.com/media/d5bd4bcc7d7da750578c924f42c3bea8/href</a></iframe><p>That’s it!, The method will calculate the item position on the screen, calculates the sliding distance and slides the view inside the listItem on scrolling the list.</p><blockquote>This blog is not about creating this animation. This is about how you can think differently and create something new. Check <a href="https://blog.mindorks.com/android-smileyrating-how-i-solved-it-9b5ee30f2c34">SmileyRating</a> for my another creation.</blockquote><p>You can download the source for this project from the repository below,</p><p><a href="https://github.com/sujithkanna/MenuCardAnimation">sujithkanna/MenuCardAnimation</a></p><p><strong>Check out all the top articles at </strong><a href="https://blog.mindorks.com/"><strong>blog.mindorks.com</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2876869d5855" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/menu-animation-android-2876869d5855">Menu Animation Android</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android SmileyRating (How I solved it?)]]></title>
            <link>https://medium.com/mindorks/android-smileyrating-how-i-solved-it-9b5ee30f2c34?source=rss-8d8ec01d99d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b5ee30f2c34</guid>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[svg]]></category>
            <category><![CDATA[smile]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[user-interface]]></category>
            <dc:creator><![CDATA[Sujith Niraikulathan]]></dc:creator>
            <pubDate>Thu, 01 Jun 2017 12:44:58 GMT</pubDate>
            <atom:updated>2017-06-01T15:52:05.288Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*23eYZjoA_GnwcGRrqXYxgg.gif" /></figure><p>Here I am going to write about how I created the <a href="https://github.com/sujithkanna/SmileyRating">SmileyRating</a> library and what are the problems I have faced. Before that, I want to thank @<a href="https://medium.com/@yousefkama/react-native-ui-challenge-1-42db390905c">Yousef Kama</a> for sharing his work experience based on <a href="https://dribbble.com/blabus">BillLabus</a>’s design.</p><p><strong>SVG -&gt; VectorDrawables -&gt; Canvas</strong></p><p>I started learning SVG to achieve this animation since we can avoid using images and simply draw paths to create simple shapes. But in android, I can’t use SVG natively without using a third party library. Instead, Android is having another image type called VectorDrawable. I started exploring it and bumped into this article(<a href="https://lewismcgeary.github.io/posts/animated-vector-drawable-pathMorphing/">link</a>) which helped me to understand path morphing animation. But that was not enough. Even if I could create different smileys and morph between them, I can’t control the animation. I can only start and stop it. I can’t pause the animation at a particular frame. So I decided to write it using Java(Android) native canvas API.</p><p><strong>Mouth</strong></p><p>The first step is to create a mouth. So according to the link, I shared you about the path morphing animation, “If you want to morph one object into another (eg: line to curve) it should have the same number of commands with the same number of parameters and same command sequence order.</p><p>eg: line to curve</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*EDQPd9PBzJ47Ppjw27PLVA.gif" /></figure><p>In this example, I just created a bezier curve using Android canvas. Bezier curve has two actual points and two control points. Two circles drawn in red color are control points and black circles are actual points. Here when I move the control points down, the curve becomes a line and when I move the control points up, the curve is formed again. Now if you see this upside down, you will get how I achieved the mouth animation.</p><p><strong>Joining curves</strong></p><p>It may seem simple to draw a bezier curve. But the problem was, I had to keep the edges curved to draw the mouth. Using one curve, that’s not possible, using two curves it is hard to maintain a curvy edge, So I came up with an idea of joining four curves together. That’s when I found out a great video about bezier curve joining(<a href="https://www.youtube.com/watch?v=Qu-QK3uoMdY">link</a>). If you are combining bezier curves, you have to make sure that the control points shares the same actual point(eg: Curve one’s end point and Curve two’s start point become same when you combine them) should be opposite to each other with same distance away from the actual point. For example, if one control point is at 90° and 30 pixels away from actual point, then the opposite control point must have to be at 270° and 30 pixels away from the actual point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*O51wm5jXIXTiP9l9nJO-1g.gif" /></figure><p>The above image is the example of two curves joined together. Here the first curve one’s EndControl point and curve two’s StartControl point is opposite to each other and took the joint(Two curves junction point) as the center point. As long as you keep these two control points opposite to each other and the same distance away from the junction point, the curve will be continuous. Like this, I joined four curves together to form the mouth of the smiley.</p><p><strong>Smiley Model</strong></p><p>The next problem I faced was managing all the coordinates required to draw the mouth(Smileys: TERRIBLE, BAD, OKAY, GOOD and GREAT). There are totally 4 curves(left, top, right and bottom) with 12 coordinates. So I created a model which reduced the complexity of creating the smiley. The basic idea is that in every smiley, the left side always looks like the right side but with small change. There are three creation states in that model.</p><ol><li>MIRROR</li><li>MIRROR_PARTIAL_INVERSE</li><li>MIRROR_INVERSE</li></ol><p><strong>Mirror</strong></p><p>In this type, I just have to provide the smiley’s center point(x, y) and left side curve’s coordinates(start, end, startControl and endControl points).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*AaZq4ZuMHXrC59RPPUMpYA.jpeg" /></figure><p>In this image, the white point represents the center of the mouth area, black circles represents control points, blue circles represents actual points and green circles are the opposite points created for the bezier curve to be formed and joined. Blue colored dashed lines represent the left side curve. Now I have to tell my model to create the right side curve by mirroring the coordinates we have now to get the right side curve and its opposite coordinate points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*iTiCZWBmkznh9Z9Jm6y9Xw.jpeg" /></figure><p>If you look closely, we now got all the coordinates to create the top and bottom curves. Yes, the green dots from the past two pictures are the control points and blue dots are the actual points of the top and bottom curves. Let’s form the bottom curve and see how it looks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*LxRBx8tk-fLOHzp4jnWDYw.jpeg" /></figure><p>Same way the top curve is also formed using the coordinates formed by this model. By adjusting the left side curve I can create different forms of smileys.</p><p>example: GOOD Smiley</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*BwyIsBh3oTkm2A26ZeQ38g.jpeg" /></figure><p><strong>MIRROR_PARTIAL_INVERSE</strong></p><p>This model is used in only one Smiley(OKAY). This smiley is nearly same as MIRROR, but with one more functionality. Here also the right side is automatically formed by mirroring the left side curve, But the right side will also be entirely flipped vertically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*4fNxQASGhnTgRjmbmXglAg.jpeg" /></figure><p>You can clearly see that the left side is mirrored and inverted on the right side. Top and bottom curve is flattened since the left and right control points are formed parallel to each other.</p><p><strong>MIRROR_INVERSE</strong></p><p>This is also similar to both MIRROR and MIRROR_PARTIAL_INVERSE. The left curve will be mirrored and this time the entire mouth of the smiley will be flipped vertically. So basically if you have coordinate for the left curve of GOOD smiley, then you can pass it here to for BAD smiley.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*RDpoOMgInWPG_o1x90kdhQ.jpeg" /></figure><p>You can see that this is exactly like GOOD smiley flipped vertically.</p><p><strong>Animate Smileys</strong></p><p>Animating is the simplest part here, all you have to do is evaluate the value between the coordinates of the smileys by the fraction of 0 to 1.</p><p>eg:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd90efa71f40cb4e464ec78190ed21e6/href">https://medium.com/media/fd90efa71f40cb4e464ec78190ed21e6/href</a></iframe><p>This example will calculate the leftCurvePointX value of the calculated smiley to be drawn. By combining all smileys you will get the morphing animation like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*qDp9YmXt-_JmLk1s-CtkGQ.gif" /><figcaption>Combined animation</figcaption></figure><p><strong>Eyes</strong></p><p>Eyes are created using arcs because eyes in smileys also should show emotions. So when you are drawing paths using SVG or in Canvas, if you close the path after drawing an arc, it will try to close the arc by drawing a line from startPoint to the endPoint of the arc. In this SmileyRating there are three eye reactions only,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*YwedQvGIj3-Xlz0Mgxaipw.jpeg" /><figcaption>Eyes</figcaption></figure><p>In the above image, I had shown all three reactions of the left eye. The right eye is, as usual, the mirror of the left image. In this picture, the first two eyes look like a sliced circle, but it is actually a half drawn arc which is closed. Not let’s animate this and see how it looks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*geS4vLa1J3u4BgGpKZAitQ.gif" /></figure><p>Those two dashed lines show the start and sweep angle of the arc. You just need to change start and sweep angles of the arc and rotate the arc to create this animation.</p><p>The link to the library is provided below:</p><p><a href="https://github.com/sujithkanna/SmileyRating">sujithkanna/SmileyRating</a></p><p><strong>Resources:</strong></p><p><a href="https://medium.com/@yousefkama/react-native-ui-challenge-1-42db390905c#.pg5pscewe">https://medium.com/@yousefkama/react-native-ui-challenge-1-42db390905c#.pg5pscewe</a></p><p><a href="https://dribbble.com/shots/2790473-Feedback">https://dribbble.com/shots/2790473-Feedback</a></p><p><a href="https://www.youtube.com/watch?v=Qu-QK3uoMdY">https://www.youtube.com/watch?v=Qu-QK3uoMdY</a></p><p><a href="https://lewismcgeary.github.io/posts/animated-vector-drawable-pathMorphing/">https://lewismcgeary.github.io/posts/animated-vector-drawable-pathMorphing/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b5ee30f2c34" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/android-smileyrating-how-i-solved-it-9b5ee30f2c34">Android SmileyRating (How I solved it?)</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>