<?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 Jannes Siebler on Medium]]></title>
        <description><![CDATA[Stories by Jannes Siebler on Medium]]></description>
        <link>https://medium.com/@sieblerjannes?source=rss-1d51f034a3cd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Ulj40xLgfpKUzXDJmFL54g.jpeg</url>
            <title>Stories by Jannes Siebler on Medium</title>
            <link>https://medium.com/@sieblerjannes?source=rss-1d51f034a3cd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 01:37:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sieblerjannes/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[JPEG compression in Android]]></title>
            <link>https://medium.com/@sieblerjannes/jpeg-compression-in-android-a44869d575e0?source=rss-1d51f034a3cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/a44869d575e0</guid>
            <category><![CDATA[jpeg]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Jannes Siebler]]></dc:creator>
            <pubDate>Sun, 27 Feb 2022 17:44:50 GMT</pubDate>
            <atom:updated>2022-02-28T09:03:04.738Z</atom:updated>
            <content:encoded><![CDATA[<p>It might sound kind of boring at first, and believe me I was annoyed as well, but soon it turned out to be one of the most interesting deep dives I have done so far.</p><h4>Why did I waste 30+ hours on JPEG compression?</h4><p>I have a client and their company is responsible to document certain locations using an Android application that I have developed for them. Their workers take a photo, a timestamp is being printed on this photo and the image is being compressed <strong>until it is smaller than 700 KB</strong>. The compression saves you almost 90% of storage (as the average image size of landscape photos were about 5.7 MB). So I created an algorithm which was compressing the image until the compressed image is smaller than 700 KB and then save it. After realizing my algorithm would sometimes need a few seconds to complete, I asked myself:</p><blockquote>Can we <strong>predict</strong> what <strong>the size of the compressed</strong> file will be, before we actually compress it?</blockquote><h4>How does JPEG compression work</h4><p>JPEG uses lossy compression, that means the quality of the image changes as we compress. We are not just doing some zip file things to the image (as f.e. PNG does). So what actually happens under the hood is kind of advanced computer science stuff (at least for a self-taught mobile developer like myself), but very interesting. There are more than one way of doing JPEG compression, but they only differ very little. Here is a short overview of <em>the most common JPEG compression:</em></p><ol><li>Image gets split into <strong>three channels</strong>: Brightness, red and blue — <strong>Y’CbCr</strong></li><li>As the human eye sees brightness better than colors, the blue and red layer gets down sampled by the factor 2 (horizontal and vertical pixels)</li><li>All channels are split into small 8x8 blocks</li><li>Each 8×8 block of each component (Y, Cb, Cr) is converted to a <a href="https://en.wikipedia.org/wiki/Frequency-domain">frequency-domain</a> representation using 2-dimensional <a href="https://en.wikipedia.org/wiki/Discrete_cosine_transform">DCT</a></li><li>Reduce the amount of information in the high frequency DCT components (<strong>Quantization)</strong></li><li><a href="https://en.wikipedia.org/wiki/JPEG#Entropy_coding">Entropy coding</a>, which is a form of lossless data compression</li></ol><p>When the whole process is done, the encoder saves a header alongside the image information, which then tells the encoder (whoever wants to show that image) how to reconstruct the image.</p><blockquote>I really, <strong>REALLY</strong> recommend watching this <a href="https://youtu.be/LFXN9PiOGtY">YouTube playlist</a> by Computerphile of how JPEG works (~35 min).</blockquote><p>After I had spent a few hours digging into all of the above, it quickly became clear: <strong>It is impossible to predict the size of a compressed JPEG without doing the actual compression </strong>(or a similar costly calculation)<strong>! </strong>So what do you do when you cannot predict something mathematically? You collect data and try to at least get close!</p><h3>The empirical approach</h3><p>In Android, JPEG compression is done using <a href="https://developer.android.com/reference/android/graphics/Bitmap#compress(android.graphics.Bitmap.CompressFormat,%20int,%20java.io.OutputStream)">Bitmap’s compress</a> function.</p><pre>public boolean compress (<a href="https://developer.android.com/reference/android/graphics/Bitmap.CompressFormat">Bitmap.CompressFormat</a> format, <br>                int quality, <br>                <a href="https://developer.android.com/reference/java/io/OutputStream">OutputStream</a> stream)</pre><p>The function takes in an Integer from<strong> 0 to 100 </strong>which is called<strong> quality.</strong> This property is called quality and NOT “compression value” because it has almost nothing to do with the resulting compressed image size.</p><figure><img alt="An Excel table with different compression ratios depending on selected compression quality in android bitmap compression" src="https://cdn-images-1.medium.com/max/1024/1*NazSnwJQBQhxcIOj0gkwxA.png" /><figcaption>A screenshot of some compression data</figcaption></figure><p>I built an app and took <strong>hundreds of photos</strong> and compressed each image from quality = 100 down to quality = 5 (in steps of 5) to record the ratio of the original file size to the compressed file for each quality value.</p><p><a href="https://github.com/Jaykocha/PhotoCompress/tree/master">GitHub - Jaykocha/PhotoCompress at master</a></p><p>Above you can find my public repository of the app I used for collecting the data.</p><h4>Brightness makes a huge difference</h4><p>Because brightness is way more important for the human eye than color, and JPEG compression reflects that, dark images with very little brightness are compressed way ‘faster’. As you can see in the below graph, a quality parameter of 90 results in a ~40% compressed file size for a dark image, but only compresses a light/detailed image to about 70%.</p><figure><img alt="Graph of JPEG compressions ratios between original file and compressed file depending on the specified quality." src="https://cdn-images-1.medium.com/max/1024/1*JJorDv5TAxao73-6HTSe7Q.png" /></figure><p>Another very interesting (and useful) finding is that <strong>starting from a quality of about 75 you lose more quality but gain less size benefits </strong>(graph becoming almost linear at this point). So the biggest benefit in reducing file size is gained from 95 to 75 quality.</p><h3>So how to get a benefit from my findings?</h3><p>Let’s consider 2 scenarios:</p><h4>1. You don’t have any file size constraints</h4><p>In this case, I would suggest you to always just compress your file using a quality parameter of <strong>75</strong>. This doesn’t hurt your image quality at all (from my findings) but saves you between 60–80 % of memory (see JPG Compression graph).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x6FHqB4dOEPcekHyi_YMnA.png" /><figcaption>The right side is the compressed version ;)</figcaption></figure><h4><strong>2.</strong> <strong>You want to specify a maximum image size after compression (or a range)</strong></h4><p>In this case, you could use my findings to select an initial quality and scale down (or up, if you want it to be in a range) from there. <strong>I created a class called CompressQuality.java for you:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b29fd18934ff394e6f87f2ec77ba52f/href">https://medium.com/media/0b29fd18934ff394e6f87f2ec77ba52f/href</a></iframe><h4>Solution to my problem (scenario 2)</h4><p>As mentioned, I was trying to do the least image compression as possible to end up with a certain max file size. So I have implemented the CompressQuality class in a function to get a compressed image between 500Kb and 700 KB in size.</p><figure><img alt="Code snippet which shows my implementation of the CompressQuality helper class" src="https://cdn-images-1.medium.com/max/1024/1*HlLh3lYKqUkXmXK6JzA9rQ.png" /></figure><blockquote>The above shows how to define <strong>a range where the compressed file should be</strong> in, f.e. between<strong> 700 KB and 500 KB. </strong>If you only want a maxKBSize you can omit the minKBSize variable.</blockquote><p>Furthermore, I share a link to a sample app where you can see a full sample app I quickly created with the above code snippet in action. Feel free to download it and try it out for yourself.</p><p><a href="https://github.com/Jaykocha/PhotoCompress">GitHub - Jaykocha/PhotoCompress: A sample app where the master branch shows how I collected JPG compression data and the branch test_impleementation shows of how the collected data could be used</a></p><h4>Follow me for more (hopefully) interesting things all around mobile developing, android, flutter and more👋!</h4><p>Also, if you are interested in developing a cross-platform app using flutter or just want to chat, please <a href="https://twitter.com/jasi_dev">contact me</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a44869d575e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android: How to create a custom alert dialog (using ViewModel)]]></title>
            <link>https://medium.com/@sieblerjannes/android-how-to-create-you-custom-alert-dialog-using-viewmodel-1b93f02d5f20?source=rss-1d51f034a3cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b93f02d5f20</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Jannes Siebler]]></dc:creator>
            <pubDate>Wed, 16 Feb 2022 14:50:07 GMT</pubDate>
            <atom:updated>2022-03-09T17:43:07.767Z</atom:updated>
            <content:encoded><![CDATA[<p>…and implement it in a maintainable, easy way.</p><figure><img alt="An alert dialog, which shows two options, a text and a headline. On top there is a red circle with a white warning icon." src="https://cdn-images-1.medium.com/max/1024/1*83cCMwChaMvL7riZ4DSV3A.jpeg" /></figure><p>See the full example on my <a href="https://github.com/Jaykocha/AlertDialogShowapp">GitHub</a>. If you only want to copy my code (yes, you can) scroll down to section <strong>easy implementation.</strong></p><h3>An overview: Architecture, files, etc.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*6Z0EizQj_7TnOpwuReB5PA.png" /><figcaption>This is all what is needed!</figcaption></figure><h4>1. Create the custom AlertDialogView</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/051296a59a079ac1efff0abe43b5d3ed/href">https://medium.com/media/051296a59a079ac1efff0abe43b5d3ed/href</a></iframe><p>The above code results in the following shape, where width and height are defined by parent (so unlike in this preview the actual alert dialog won’t cover the whole screen).</p><figure><img alt="A screenshot of a rectangular shape with a half circle cut out at the top" src="https://cdn-images-1.medium.com/max/709/1*AqaGdnuKIxdWBnKvKnzICg.jpeg" /></figure><h4>2. Create the layout resource for my dialog</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3737e6703f804766157ef24df7abe09/href">https://medium.com/media/f3737e6703f804766157ef24df7abe09/href</a></iframe><p>This results in the following shape:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*lUOp2Uq8ge7wYjvv1gKcsw.png" /><figcaption>Note that I set the paint color to Color.GRAY of my AlertDialogView for demonstration</figcaption></figure><h4>3. Create an enum which holds your alert categories</h4><p>We humans are creatures of habits, so let’s design our dialogs this way. For this example I defined 3 categories which should use the same styling.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5cbebebc814c662616016783a44c21b6/href">https://medium.com/media/5cbebebc814c662616016783a44c21b6/href</a></iframe><h4>4. Create an enum which hold all alert dialog types</h4><p>As comment you can see the category each AlertType belongs to.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/baa03a0ab36a7b7f10c59c4482dcf11b/href">https://medium.com/media/baa03a0ab36a7b7f10c59c4482dcf11b/href</a></iframe><h4>5. Create AlertOptions (defines how to build each AlertType’s dialog)</h4><p>This class holds a static function <em>create </em>which is used to get an AlertOptions object depending on the passed AlertType. I omitted getters, setters and some other alert types for this code example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9a44949e3fcfbefdc2d54a5c1a741be/href">https://medium.com/media/f9a44949e3fcfbefdc2d54a5c1a741be/href</a></iframe><p>Note the function “updateText(String newText)”, which returns a new AlertOptions object with an updated text. <strong>This is needed for the dynamic alert. </strong>If you would want to dynamically update more properties of the dialog, here is where you would need to add a new update function.</p><h4>6. Create my ViewModel class</h4><p><strong>This is needed to survive configuration changes, like a screen rotation.</strong> It is also handy to cancel the alert dialog from a different activity in your app. You could for example display a warning when you have no internet connection and automatically dismiss it onAvailable(). <strong>The MutableLiveData objects can be observed though the LiveData functions (getOptions and isCanceled). </strong>This is what the alert dialog does.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d0b62f35d9024293aa2e5bf890d6e76/href">https://medium.com/media/3d0b62f35d9024293aa2e5bf890d6e76/href</a></iframe><h4>7. Create a DialogManager to instantiate MyAlertDialogViewModel and show dialog</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77bc22e6d7f9f42a5f75f59ace22910b/href">https://medium.com/media/77bc22e6d7f9f42a5f75f59ace22910b/href</a></iframe><h4>8. Add all pieces together (MyAlertDialog.java)</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d68007890a31596fe88b0d319316a602/href">https://medium.com/media/d68007890a31596fe88b0d319316a602/href</a></iframe><p>Don’t miss the interface all the was at the bottom of this file which is how we tell the calling activity or fragment what option was chosen. The alertDialogMainOption is called when the main button is pressed (button with a background color).</p><figure><img alt="Alert dialog which shows the two options to click on" src="https://cdn-images-1.medium.com/max/720/1*RhOF2MuW_ZP98vRmquVyOg.jpeg" /><figcaption>Alternative option and main option.</figcaption></figure><h3>9. MainActivity.java</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c3a2c331939e8453d4cd8825fb47098/href">https://medium.com/media/5c3a2c331939e8453d4cd8825fb47098/href</a></iframe><h3>10. Easy implementation (just copy paste basically)</h3><ol><li>Download the files from my <a href="https://github.com/Jaykocha/AlertDialogShowapp">github</a></li><li>Copy and paste everything from folders <strong>drawable</strong>, <strong>layout</strong> and java/jasi/example/alertdialogshowcase/<strong>alertdialog</strong>. Only ignore MainActivity.java and activity_main.xml!</li><li>Implement the AlertDialogInterface at the Activity or Fragement from where you want to call the dialog. You are then forced to implement the callback methods. :</li></ol><pre>public MyActivity extends AppCompatActivity implements MyAlertDialog.AlertDialogInterface {</pre><pre>[other code of you...]</pre><pre>@Override<br><strong>public void </strong>alertDialogMainOption(AlertType type) {<br>    Log.v(&quot;DialogMainOption&quot;, type.toString);<br>    //Do what you want here<br>}<br><br>@Override<br><strong>public void </strong>alertDialogAlternativeOption(AlertType type) {<br>    Log.v(&quot;DialogAlternativeOption&quot;, type.toString);       <br>    //Do what you want here<br>}<br>}</pre><p>4. Create a field variable for MyAlertDialogViewModel, f.e.</p><pre>private MyAlertDialogViewModel alertDialogModel;</pre><p>5. 1. <strong>Calling from activity: </strong>Instantiate the MyAlertDialoViewModel in the onCreate method as such:</p><pre>alertDialogModel = AlertDialogManager.<em>instantiateViewModel</em>(this);</pre><p>5.2 <strong>Calling from fragment: </strong>Instantiate the ViewModel in the onCreateView method as such:</p><pre><strong>alertViewModel </strong>= AlertDialogManager.<em>initializeViewModel</em>(requireActivity());</pre><p>6. 1.<strong> Show the dialog from activity:</strong></p><pre>AlertDialogManager.<em>showMyDialog</em>(<strong>this</strong>,<br>        AlertType.examplePrimary, <strong>alertDialogViewModel</strong>, <strong>this</strong>);</pre><p>6. 2. <strong>Show the dialog from fragment:</strong></p><pre>AlertDialogManager.<em>showMyDialog</em>(<strong>this</strong>,<br>        AlertType.examplePrimary, <strong>alertDialogViewModel</strong>, requireActivity());</pre><p>7. Customize as you wish</p><h3>Done!</h3><p>I know that this article is fairly complex and I probably would need to make a bigger series out of it, explaining what happens under the hood and why my approach works so great. But, no time :(.</p><p>So if you want to understand why it works, check out the following resources:</p><ul><li>What is a <a href="https://developer.android.com/topic/libraries/architecture/viewmodel?hl=en">ViewModel</a></li><li>What is <a href="https://developer.android.com/topic/libraries/architecture/livedata?hl=en">LiveData</a></li><li>What is a <a href="https://developer.android.com/reference/android/app/DialogFragment">DialogFragment</a></li></ul><p>If you have any questions please write me on <a href="https://twitter.com/jasi_dev">twitter</a> and I will help you as much as I can.</p><h4>Thanks for reading, leave me a follow or just give me a little virtual clap if I could help you.</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b93f02d5f20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make text scrollable in Figma]]></title>
            <link>https://medium.com/design-bootcamp/make-text-scrollable-in-figma-544bed28b749?source=rss-1d51f034a3cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/544bed28b749</guid>
            <category><![CDATA[ux-design]]></category>
            <category><![CDATA[figma]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[first-post]]></category>
            <category><![CDATA[ux]]></category>
            <dc:creator><![CDATA[Jannes Siebler]]></dc:creator>
            <pubDate>Fri, 14 Jan 2022 13:55:21 GMT</pubDate>
            <atom:updated>2022-01-19T05:29:33.348Z</atom:updated>
            <content:encoded><![CDATA[<p>If you came from Google, you are probably a noob just like myself when I was trying to get text scrollable in a certain area.</p><figure><img alt="Drawing of man sitting on desk with a sad face and a lama hat" src="https://cdn-images-1.medium.com/max/400/1*cLdllTRA4rkNa9TstccJyw.png" /><figcaption>Created with blush, by <a href="https://blush.design/artists/RyUTVuP8G4QeAAEEQgug/pablo-stanley">Pablo Stanley</a></figcaption></figure><p>Now, after 3 hours of sweat and tears I should probably use a different title (because I know now), but I want to save other noobs my pain and hopefully Google will guide them to this article. It is my first by the way, so whoever reads it, be nice :).</p><h3>Here is how to make everything in a rectangular shape scrollable (even text)!</h3><p>A step by step guide (from noob to noob):</p><ol><li>Press ‘F’ on your keyboard and draw a rectangle. In <strong>this rectangle you want its contents to be scrollable</strong>.</li></ol><p>2. Set your scrollable frame to ‘Clip content’.</p><figure><img alt="A screenshot that shows the selected frame whose contents we want to make scrollable. On the right side the option clip content is highlighted as it should be selected." src="https://cdn-images-1.medium.com/max/505/1*qLZ4Kr0F6IanCl8H_KO4VQ.png" /><figcaption>You find this on the right side of your screen ;)</figcaption></figure><p>3. Place any content you want as a child of your ‘scrollable frame’. I chose a very long text and an image.</p><figure><img alt="It shows a screenshot of figma that shows the scrollable frame and an image with text inside of it. The text is cut off at the bottom." src="https://cdn-images-1.medium.com/max/525/1*7Hew9FqiUtMoBgMbmZYFKg.png" /><figcaption>Note: How on the left <strong>monalisa1</strong> and <strong>‘Lorem impsum…’</strong> are <strong>children of Scrollable frame.</strong></figcaption></figure><p>4. Select your scrollable frame and navigate to the prototype tab. There you have the attribute ‘Overflow scrolling’. Select whatever scrolling behaviour you want to achieve. In my case (my text is overflowing vertically to the bottom), I select <strong>‘vertical scrolling’</strong>.</p><figure><img alt="A screenshot of figma that show the scrollable frame and its contents (image and text) and on the right side the option “vertical scrolling” is highlighted as this is what has to selected to achieve vertical scrolling behaviour." src="https://cdn-images-1.medium.com/max/526/1*KKTGMIiJSBpCVu79BLaUQw.png" /></figure><p>5. That is it. You are done. You can now move your scrolling frame around and even make it a component if you wish to.</p><h4>Follow me if you want more noob content in the future.</h4><p>Just kidding, I am actually an android and flutter developer, who is new to UX design software (like figma).</p><p><strong>I plan to soon publish more articles of how I make a living as a self-taught programmer and how I helped a business to become more successful by convincing them to pay me for an app. And much more…</strong></p><p>So for real now, follow me :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=544bed28b749" width="1" height="1" alt=""><hr><p><a href="https://medium.com/design-bootcamp/make-text-scrollable-in-figma-544bed28b749">Make text scrollable in Figma</a> was originally published in <a href="https://medium.com/design-bootcamp">Bootcamp</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>