<?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 Balu Sangem on Medium]]></title>
        <description><![CDATA[Stories by Balu Sangem on Medium]]></description>
        <link>https://medium.com/@balusangem?source=rss-73eae3d6d9d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6Hah2_mfQSEjlBTmUMeWIQ.png</url>
            <title>Stories by Balu Sangem on Medium</title>
            <link>https://medium.com/@balusangem?source=rss-73eae3d6d9d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 09:59:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@balusangem/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[A class for converting encoded images (like PNG, JPEG, WEBP, GIF, or HEIF) into Drawable or Bitmap…]]></title>
            <link>https://medium.com/nosort/a-class-for-converting-encoded-images-like-png-jpeg-webp-gif-or-heif-into-drawable-or-6a7219319abc?source=rss-73eae3d6d9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a7219319abc</guid>
            <category><![CDATA[android-p]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[bitmap]]></category>
            <category><![CDATA[imagedecorder]]></category>
            <dc:creator><![CDATA[Balu Sangem]]></dc:creator>
            <pubDate>Fri, 29 Jun 2018 10:53:21 GMT</pubDate>
            <atom:updated>2018-09-05T13:26:10.542Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A class for converting encoded images (like </em><em>PNG, </em><em>JPEG, </em><em>WEBP, </em><em>GIF, or </em><em>HEIF) into </em><a href="https://developer.android.com/reference/android/graphics/drawable/Drawable.html"><em>Drawable</em></a><em> or </em><a href="https://developer.android.com/reference/android/graphics/Bitmap.html"><em>Bitmap</em></a><em> objects.</em></p><blockquote>ImageDecoder class is available from android P the Framework so we can only use it on devices running P or later for now.</blockquote><ul><li>First we have to create <a href="https://developer.android.com/reference/android/graphics/ImageDecoder.Source.html">Source</a> using one of the createSource overloads.</li></ul><pre>val source = ImageDecoder.createSource(X);<br>//Where <em>X is a file or id from resource or name from assets</em></pre><ul><li>To get image with default configurations , we can use decodeDrawable(source)</li></ul><p>Complete Code to get bitmap with default configurations</p><pre>//getting image from assets<strong><br>val </strong>source = ImageDecoder.createSource(<em>assets</em>, <strong>&quot;image.jpg&quot;</strong>)<br><strong>val </strong>bitmap = ImageDecoder.decodeBitmap(source) //default<br>imageView.setImageBitmap(bitmap)</pre><p>Same way we can create Drawable with default configurations</p><pre><em>//getting image form assets<br>val source = ImageDecoder.createSource(assets,&quot;</em><strong>image</strong><em>.jpg&quot;)<br>val drawable = ImageDecoder.decodeDrawable(source)<br>imageView.setImageDrawable(drawable)</em></pre><p>Result is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*WGORDTg3tfTYr9FDXY3mig.png" /><figcaption>Screenshot with default configurations</figcaption></figure><p>To change default settings, we can pass <em>OnHeaderDecodedListener</em> as listener for <em>decodeDrawable(source,listenr)</em></p><ul><li>For Example,to create a image with width and height ,call setTargetSize(width,height)</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a46ab82d70c1f32e7acc07b6a95cc5d/href">https://medium.com/media/0a46ab82d70c1f32e7acc07b6a95cc5d/href</a></iframe><p>OnHeaderDecodedListener interface has single methodonHeaderDecoded(decoder,imageinfo,source)</p><ul><li>decoder (ImageDecoder) : the object performing the decode,</li><li>imageinfo (ImageDecoder.ImageInfo) : information about the encoded image for example height and width.</li><li>source (ImageDecorder.Source) : object that created decoder</li></ul><p>If decoded image is GIF or WEBP decodeResource will return an <a href="https://developer.android.com/reference/android/graphics/drawable/AnimatedImageDrawable">AnimatedImageDrawable</a> , To start animation call start() on drawble.</p><pre><strong>val </strong>drawable = ImageDecoder.decodeDrawable(source)<br><strong>if </strong>(drawable <strong>is </strong>AnimatedImageDrawable) {<br>    drawable.start()<br>}</pre><h4>Creating a Circular Drawable using ImageDecoder’s PostProcessor</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6aa4f04faa4c068f7ce284cf6f840acb/href">https://medium.com/media/6aa4f04faa4c068f7ce284cf6f840acb/href</a></iframe><p>Result is :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*ao7xQ_xmVRh6JXRMs5mBlQ.png" /><figcaption>Screenshot after using post processor to create Circular Drawable</figcaption></figure><h4>Extras</h4><ul><li>Bitmap or Drawable created by ImageDecorder is Immutable (isMutable() returns fasle ) , these properties can be changed by using setMutableRequired(true) (only works for Bitmap)</li><li>If the encoded image is incomplete or contains an error, or if an <a href="https://developer.android.com/reference/java/lang/Exception.html">Exception</a> occurs during decoding, a DecodeException will be thrown. use setOnPartialImageListener on decoder to show partial Image.</li></ul><p>Thanks for Reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a7219319abc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nosort/a-class-for-converting-encoded-images-like-png-jpeg-webp-gif-or-heif-into-drawable-or-6a7219319abc">A class for converting encoded images (like PNG, JPEG, WEBP, GIF, or HEIF) into Drawable or Bitmap…</a> was originally published in <a href="https://medium.com/nosort">NOSORT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[App Startup States and issues]]></title>
            <link>https://medium.com/nosort/users-expect-apps-to-be-responsive-and-fast-to-launch-c98238e743c1?source=rss-73eae3d6d9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c98238e743c1</guid>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Balu Sangem]]></dc:creator>
            <pubDate>Tue, 26 Jun 2018 13:23:08 GMT</pubDate>
            <atom:updated>2018-06-26T13:25:51.498Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Users expect apps to be responsive and fast to launch</blockquote><p>When you launch an app , it can take place in one of three states, each has some tasks to complete which takes time.if the time increases that is a problem, because users expect apps to launch fast.</p><p>so we will look at those states in detail and the issues slowing down launching.</p><blockquote>The system process displays a blank screen until the app has finished rendering the activity</blockquote><p>When you launch an app,launch can take place in one of <strong>three states</strong> namely <strong><em>cold start</em></strong><em>,</em><strong><em>warm start</em></strong><em> </em><strong><em>and hot start</em></strong><em>. </em>Each affecting how long it takes for your app to become visible to the user.</p><h3>Cold start</h3><p>A Cold start refers to app starting from scratch (Systems process not yet created Apps process yet)</p><p>Cold start happens in cases where your <em>app being launched for the first time</em></p><ul><li>since device booted.</li><li>since system killed app process.</li></ul><blockquote>Cold start takes more time, compared to other two launching states</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*xh0XsIMV0zE3vtyTuzh0Qg.png" /><figcaption><a href="https://developer.android.com/topic/performance/images/cold-launch.png">https://developer.android.com/topic/performance/images/cold-launch.png</a></figcaption></figure><p>First System process has three tasks to do:</p><ul><li>Loading and launching the app.</li><li>Displaying a blank window for the app immediately after launch.</li><li>Creating app process.</li></ul><p><em>After System create app process, app process is responsible for next stages</em></p><p>These stages are :</p><ul><li>Creating app object</li><li>Launching <em>main thread</em>.</li><li>Creating the main activity.</li><li>Inflating views.</li><li>Laying out the screen.</li><li>Performing first draw.</li></ul><p>After app process completing first draw,the system process replaces the currently displayed blank window, replacing it with the main activity. At this point, the user can start using the app.</p><h3>Hot start</h3><p>In this state, system brings activity to foreground.If all application’s activities are still present in memory, then the app can avoid having to repeat object initialization, layout inflation, and rendering.so this is much simpler and lower-overhead than cold start.</p><p>If app objects removed from memory in response to memory trimming events, then all objects need to be recreated in response to the hot start event.</p><h3>Warm start</h3><p>A warm start encompasses some subset of the operations that take place during a cold start.</p><p>There are many potential states that could be considered warm starts. For instance:</p><ul><li>User backs out of your app,but then re-launches it, then recreation of activity will be done by calling onCreate() of main activity again.</li><li>System removes app from memory, but your re-launches it, this time process and app both have to be restarted. bu this time task can be befit somewhat from the saved instance state bundle passed into onCreate()</li></ul><p>warm start represents less overhead than a hot start</p><p><em>Android vitals considers your app’s startup times excessive when the app’s:</em></p><ul><li><em>Cold startup takes 5 seconds or longer.</em></li><li><em>Warm startup takes 2 seconds or longer.</em></li><li><em>Hot startup takes 1.5 seconds or longer.</em></li></ul><h3>issues that often affect apps’ startup performance</h3><ul><li><strong>Heavy app initialization</strong></li><li><strong>Heavy activity initialization</strong></li><li><strong>Themed launch screens</strong></li></ul><h4>Heavy app initialization</h4><p>There is a problem if your code overrides Applications onCreate() and executing heavy work in it.Your app may waste time during startup if your Application sub classes perform initialization that don’t need to be done yet.</p><p><strong>Solutions to the problem</strong></p><p>Initializing only those objects that are immediately needed.For example, rather than creating global static objects, instead, move to a singleton pattern.</p><h4>Heavy activity initialization</h4><p>Activity creation often entails a lot of high-overhead work. Often, there are opportunities to optimize this work to achieve performance improvements. Such common issues include:</p><ul><li>Inflating large or complex layouts.</li><li>Blocking screen drawing on disk, or network I/O.</li><li>Loading and decoding bitmaps.</li><li>Rasterizing <em>VectorDrawable</em> objects.</li><li>Initialization of other subsystems of the activity.</li></ul><p><strong>Solutions to the problem</strong></p><p>There are many potential bottlenecks, but two common problems and remedies are as follows:</p><ul><li>The larger your view hierarchy, the more time the app takes to inflate it. So flatten your hierarchy by removing redundant and nested layouts and Not inflating parts of the UI that do not need to be visible during launch. Instead, use use a <em>ViewStub</em> object as a placeholder for sub-hierarchies that the app can inflate at a more appropriate time.</li><li>Having all of your resource initialization on the main thread can also slow down startup. So move all resource initialization so that the app can perform it on a different thread and first load and display views, later update visual properties which are dependent on bitmaps and other resources.</li></ul><h4>Themed launch screens</h4><p>You may wish to theme your app’s loading experience,Doing so can hide a slow activity launch.</p><p>A common way to implement a themed launch screen is to use thewindowDisablePreviewtheme attribute to turn off the initial blank screen that the system process draws when launching the app. It forces the user to wait with no feedback while the activity launches, making them wonder if the app is functioning properly.</p><p><strong>Solutions to the problem</strong></p><p>Rather than disabling the preview window, You can use the activity’s windowBackground theme attribute to provide a simple custom drawable for the starting activity.</p><p>Example is : <a href="https://www.bignerdranch.com/blog/splash-screens-the-right-way/">https://www.bignerdranch.com/blog/splash-screens-the-right-way/</a></p><p>Summarized vesion of : <a href="https://developer.android.com/topic/performance/vitals/launch-time">https://developer.android.com/topic/performance/vitals/launch-time</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c98238e743c1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nosort/users-expect-apps-to-be-responsive-and-fast-to-launch-c98238e743c1">App Startup States and issues</a> was originally published in <a href="https://medium.com/nosort">NOSORT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Playing Video in ARCore using OpengGL]]></title>
            <link>https://medium.com/nosort/playing-video-in-arcore-using-openggl-a81ff62f7a6d?source=rss-73eae3d6d9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a81ff62f7a6d</guid>
            <category><![CDATA[arcore]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[sceneform]]></category>
            <category><![CDATA[ar]]></category>
            <dc:creator><![CDATA[Balu Sangem]]></dc:creator>
            <pubDate>Thu, 14 Jun 2018 13:10:47 GMT</pubDate>
            <atom:updated>2018-08-20T07:51:35.211Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Update 20/August/2018 : Support for playing video in sceneform added in sceneform1.4, see </em><a href="https://github.com/google-ar/sceneform-android-sdk/issues/9#issuecomment-410066332"><em>here</em></a></p><p><em>For playing videos using sceneform sdk see</em><a href="https://github.com/google-ar/sceneform-android-sdk/tree/master/chromakeyvideo"><em> this sample</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tt-jx1c04jYEvKoWEqwKgA.png" /><figcaption>Screenshot</figcaption></figure><p>Google released Sceneform but it doesn’t support VideoView to play video even though it gave support for Android Views with <a href="https://developers.google.com/ar/reference/java/com/google/ar/sceneform/rendering/ViewRenderable">ViewRenderable</a> ,we have to use OpenGL.</p><p>You can try Sceneform from here : <a href="https://github.com/google-ar/sceneform-android-sdk">https://github.com/google-ar/sceneform-android-sdk</a>.</p><p>We are going to modify the ARCore samples project : <strong><em>hello_ar_java</em></strong><em> </em>from ARCore SDK repo, you can download it from here : <a href="https://github.com/google-ar/arcore-android-sdk">https://github.com/google-ar/arcore-android-sdk</a>.</p><p>As you can see in project structure <em>Render classes</em> are the classes which are placing object in AR Scene.</p><p>We are going to create a new ViewRenderer.java which renders video in AR Scence.</p><p>ViewRenderer.java contains 4 main methods : <em>createOnGLThread(),update(), draw(),start().</em></p><p>Initialize every thing in <em>createOnGLThread</em> method().</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7377f81df8e0382792b57ac1c5af8753/href">https://medium.com/media/7377f81df8e0382792b57ac1c5af8753/href</a></iframe><p>by calling <em>update()</em> method you can change <em>model matrix</em>, you can scale and translate video by updating model matrix here.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af1de6c24089a251278ed97f962ca6af/href">https://medium.com/media/af1de6c24089a251278ed97f962ca6af/href</a></iframe><p><em>draw()</em> renders video by getting <em>view matrix</em> and <em>projection matrix</em> from ARCore Camera (frame.getCamera()).</p><p>we update texture and set dimensions for video frame, finally create a model view projection matrix to render video on screen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40eee06e3192dac87de1157e2fc979b5/href">https://medium.com/media/40eee06e3192dac87de1157e2fc979b5/href</a></iframe><p>You can get full ViewRenderer.java from <a href="https://gist.github.com/BALUSANGEM/47dc82fb4542bacbb35960510580e1a6">here</a>.</p><h4>Using ViewRenderer.java in your Activity</h4><p>Create object of VideoRenderer.</p><p>private final VideoRenderer videoRenderer = new VideoRenderer()</p><p>call videoRenderer.createOnGlThread(); inside onSurfaceCreated(GL10 gl,EGLConfig config).</p><p>In onDrawFrame(GL10 gl) method create a movie anchor.</p><pre><strong>if </strong>(<strong>mMovieAnchor </strong>== <strong>null</strong>) {<br>    <strong>mMovieAnchor </strong>= hit.createAnchor();<br>} <strong>else </strong>{<br>    <strong>anchors</strong>.add(hit.createAnchor());<br>}</pre><p>at the end of <em>onDrawFrame()</em> method you can use this code to update video pose.</p><pre><strong>if </strong>(<strong>mMovieAnchor </strong>!= <strong>null</strong>) {<em><br>    </em><strong>if </strong>(!<strong>videoRenderer</strong>.isStarted()) {<br>        <strong>videoRenderer</strong>.play(<strong>&quot;video_name.mp4&quot;</strong>, <strong>this</strong>);<br>    }<br>    <strong>mMovieAnchor</strong>.getPose().toMatrix(<strong>mAnchorMatrix</strong>, 0);<br>    <strong>videoRenderer</strong>.update(<strong>mAnchorMatrix</strong>);<br>    <strong>videoRenderer</strong>.draw(viewmtx, projmtx);<br>}</pre><p>You can find modified HelloARActivity.java from <a href="https://gist.github.com/BALUSANGEM/51e956ad090454c32e54055945a82b3b">here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a81ff62f7a6d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nosort/playing-video-in-arcore-using-openggl-a81ff62f7a6d">Playing Video in ARCore using OpengGL</a> was originally published in <a href="https://medium.com/nosort">NOSORT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding views on top of UnityPlayer in UnityPlayerActivity]]></title>
            <link>https://medium.com/nosort/adding-views-on-top-of-unityplayer-in-unityplayeractivity-e76240799c82?source=rss-73eae3d6d9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e76240799c82</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Balu Sangem]]></dc:creator>
            <pubDate>Sun, 27 Aug 2017 09:49:50 GMT</pubDate>
            <atom:updated>2017-08-27T11:02:09.242Z</atom:updated>
            <content:encoded><![CDATA[<p>Many developers now a days trying to integrate Unity with Android, and they are successful. But the problem is adding android views on top of Unity Player.</p><p>When we get android project from Unity , we will get UnityPlayerActivity.class, This class onCreate() looks like this,</p><pre>UnityPlayer mUnityPlayer= new UnityPlayer(this);<br>setContentView(mUnityPlayer);<br>mUnityPlayer.requestFocus();</pre><p>In above code we can see , UnityPlayerset as a view.</p><p>Instead of setting UnityPlayer as a view, <em>set Layout </em>from <em>resources</em><strong> </strong>setContentView(R.layout.activity_unity_player) .</p><p>Now onCreate() method looks like this</p><pre>UnityPlayer mUnityPlayer= new UnityPlayer(this);<br>setContentView(R.layout.activity_unity_player)<br>mUnityPlayer.requestFocus();</pre><p>Create layout R.layout.activity_unity_player and change layout as below,</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;FrameLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:orientation=&quot;vertical&quot;     android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:id=&quot;@+id/main_layout&quot;&gt;<br><br>    &lt;FrameLayout<br>        android:id=&quot;@+id/unity_player_layout&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>        android:background=&quot;@color/toolbar_color&quot;<br>    android:layout_height=&quot;match_parent&quot;/&gt;</pre><pre>    &lt;ImageButton<br>        android:id=&quot;@+id/back_button&quot;<br>        android:src=&quot;@mipmap/done&quot;<br>        android:background=&quot;@null&quot;<br>        android:layout_margin=&quot;@dimen/dp_10&quot;<br>        android:layout_gravity=&quot;bottom|start&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot; /&gt;</pre><pre>    &lt;ImageButton<br>        android:id=&quot;@+id/done_button&quot;<br>        android:src=&quot;@mipmap/done&quot;<br>        android:layout_margin=&quot;@dimen/dp_10&quot;<br>        android:layout_gravity=&quot;bottom|end&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot; /&gt;</pre><pre>&lt;/FrameLayout&gt;</pre><p>We added layout for UnityPlayerActivity.class , to add <strong>Unity Player </strong>to that layout ,</p><p>change<strong> </strong>UnityPlayerActivity.class in onCreate() method:</p><pre>        UnityPlayer mUnityPlayer = new UnityPlayer(this);<br>        setContentView(R.layout.unity_player_activity_layout);<br>        FrameLayout frameLayout = (FrameLayout)findViewById(R.id.unity_player_layout);<br>        frameLayout.addView(mUnityPlayer.getView());<br>        mUnityPlayer.requestFocus();</pre><p>Now we have added Unity Player and two custom Image Buttons on top of that Unity Player .</p><p>Happy coding , Good luck :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e76240799c82" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nosort/adding-views-on-top-of-unityplayer-in-unityplayeractivity-e76240799c82">Adding views on top of UnityPlayer in UnityPlayerActivity</a> was originally published in <a href="https://medium.com/nosort">NOSORT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>