<?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 Jieyi Wu on Medium]]></title>
        <description><![CDATA[Stories by Jieyi Wu on Medium]]></description>
        <link>https://medium.com/@pokkbaby?source=rss-19d9fbedc392------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fGt58LME1MKpnABcYWhkBQ.jpeg</url>
            <title>Stories by Jieyi Wu on Medium</title>
            <link>https://medium.com/@pokkbaby?source=rss-19d9fbedc392------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 03:07:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pokkbaby/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[Different way to use Search View’s collapsing and expanding]]></title>
            <link>https://medium.com/@pokkbaby/how-to-fix-the-search-views-collapsing-and-expanding-c9340662a0ee?source=rss-19d9fbedc392------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9340662a0ee</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[expand]]></category>
            <category><![CDATA[searchview]]></category>
            <dc:creator><![CDATA[Jieyi Wu]]></dc:creator>
            <pubDate>Fri, 15 Jun 2018 09:57:02 GMT</pubDate>
            <atom:updated>2018-06-20T01:20:42.006Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*Kw997k-VpjLC7rxsZhxN3Q.jpeg" /><figcaption><a href="https://businessingmag.com/2825/strategy/3-questions-to-ask-yourself-before-expanding-your-business/">https://businessingmag.com/2825/strategy/3-questions-to-ask-yourself-before-expanding-your-business/</a></figcaption></figure><p>Recently I’m running a project and was facing a weird issue when I used the <strong>SearchView </strong>on the navigation bar with page title and a hamburger menu.</p><p>Constraints Layout is used in this project everywhere because the official recommended and the <strong>onLayout</strong> function could be reduced running one time and improve the efficiency. Also, the nest layouts could be reduced, XML file will be readable. 😉</p><h3>Issue 😑</h3><p>I know we’re using <strong>Toolbar</strong> component in the <strong>SearchView</strong> normally. But sometimes, we will use it in our customization layout, FrameLayout, ConstrainLayout, … etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*g_kxyQRG1O40hHywTCnVNg.png" /></figure><p>When the <strong>SearchView </strong>is used with them, everything is beautiful, you won’t get any trouble!</p><p>But once you put <strong>SearchView</strong> in the other components or layouts together like the left figure, I believe that you will spend a while for that why it becomes that not like you think.</p><p>This pic is that I put SearchView in the <strong>ConstrainLayout</strong>, and when I click the <em>magnifier icon</em>, the search bar will be expanded surely. And you can try again after you click <em>cancel icon</em> again, the <strong>SearchView</strong> will run to left side.</p><p>It must suppose to return to original place after triggered the <em>cancel icon</em>. That’s unbelievable. <strong>WHY?WHY?</strong></p><p>Or you can try many ways to adjust the SearchView’s layout. The result is not same as you think. 😭😭</p><h3>How to solve?!</h3><p>I’ve searched and tried a lots solutions from Stack overflow, or someone’s blog websites. Unfortunately, I couldn’t find a good way to fix it 😤</p><p>Only me can help myself, my thinking is as the following</p><ol><li>Toolbar inherits from FrameLayout.</li><li>After collapsing the SearchView, the position will be aligned to the left side on the navigation bar.</li><li>Layout width will be changed (because there are few layouts inside of the SearchView).</li></ol><p>I use it as the same way from Toolbar layout, just put <strong>SearchView</strong> into <strong>FrameLayout.</strong></p><p>And the initialized layout is the same as the normal icon’s layout size, for example: 24dp x 24dp, 46dp x 46dp… and set it at the right side(this’s my case. It can be set anywhere you need). And you should measure the width where its bound is after the magnifier icon you clicked.</p><p>Then, booom!</p><p>This’s like the real toolbar what I need. I’m glad if this solution will be able to solve your problem the same as me.</p><p>Once you have a better solution, please feel free to share to me! 😁😁</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9340662a0ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A easy way to build DialogFragment]]></title>
            <link>https://medium.com/@pokkbaby/a-easy-way-to-build-dialogfragment-53c6e2d2afec?source=rss-19d9fbedc392------2</link>
            <guid isPermaLink="false">https://medium.com/p/53c6e2d2afec</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[dialog]]></category>
            <category><![CDATA[libraries]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Jieyi Wu]]></dc:creator>
            <pubDate>Mon, 05 Feb 2018 12:09:49 GMT</pubDate>
            <atom:updated>2018-06-06T12:07:16.963Z</atom:updated>
            <content:encoded><![CDATA[<p>To use a FragmentDialog, we don’t have to write a lot of code. Android SDK has already simpled it. <strong><em>BUT</em></strong>! There is always a ‘<strong><em>BUT</em></strong>’ LOL. I still feel that could be simpler to use so I made a dialog builder for creating a DialogFragment!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*CO-vfPccLvGr6OPBvxObbw.jpeg" /></figure><h3>Problem?!</h3><p>There’s no problem here XD Every time developers make the similar boilerplate in order to create a DialogFragment by the builder the official providers. It’s not so bad but just not simple enough. Also, each of times we’dlike to use them, the similar. code will be everywhere! The same pattern, the same code, the same way to do again and again. 😩</p><h3>A good idea and a pattern</h3><p>Fortunately, there’s a well-known pattern everyone uses it!</p><p>That’s <strong><em>Builder Pattern!</em></strong></p><p>We can use a cleaner and less code to create a DialogFragment!</p><p>Besides, this DialogFragment builder also supports the <strong>data binding</strong> and normal <strong>findByView </strong>if you need to use it!</p><p>I’ve written the <strong><em>HOW TO USE</em></strong> in my repository here. Here I’d like to show you it how easy to create it 😄</p><p>The Kotlin code is the below,</p><pre>QuickDialogFragment.Builder(this) {<br>    // Here is your customize layout.<br>    viewResCustom = R.layout.fragment_dialog_test<br>    // You can get the view object here and dialog fragment.<br>    fetchComponents = { v, df -&gt;<br>        v.btn.setOnClickListener { /* What you want to do! */ }<br>        v.tv.text = &quot;I was clicked!&quot;<br>    }<br>}.build().show()</pre><p>It’s pretty easy to use it. I also attach the demo animation to you here!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*2PD8ov3qYDeNRVbaJ_-giQ.gif" /><figcaption>Quick Dialog Fragment</figcaption></figure><p>Enjoy it! ✨</p><p>If you have any question or which part is not good enough. Please fell free to tell me. 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53c6e2d2afec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Don’t have to release RecyclerView’s ViewHolder]]></title>
            <link>https://medium.com/@pokkbaby/dont-have-to-release-recyclerview-s-viewholder-c6c42584a076?source=rss-19d9fbedc392------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6c42584a076</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[recyclerview]]></category>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[adapter]]></category>
            <category><![CDATA[viewmodel]]></category>
            <dc:creator><![CDATA[Jieyi Wu]]></dc:creator>
            <pubDate>Tue, 16 Jan 2018 15:45:12 GMT</pubDate>
            <atom:updated>2018-01-16T15:54:16.329Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zVqqI9N0STCAd1n5pLWuQQ.png" /><figcaption><a href="http://www.andevcon.com/news/10-recyclerview-android-libraries">http://www.andevcon.com/news/10-recyclerview-android-libraries</a></figcaption></figure><p>This article is about what I faced a big issue I couldn’t fix it smoothly. I spent a whole day finding this problem. Hope my experience could help who is facing the same problem with me.</p><h3>Issue</h3><p>I’m using MVVM architecture for developing my side project. I think I should follow this architecture’s concept in whole app, including <strong>activity</strong>, <strong>fragment</strong>, <strong>service</strong>, <strong>recyclerview</strong>, …, etc.</p><p>In this app, I use <strong>recyclerview</strong> massively, we can see it in the most of the fragments XD because it easy to show a big data to a user.</p><p>In my architecture, each of the items of the recyclerview has a holder which is <strong>ViewModel</strong>. My code will be as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/087535122281d7c941d111e7d71b260a/href">https://medium.com/media/087535122281d7c941d111e7d71b260a/href</a></iframe><p>The adapter, I did encapsulate and separate the <strong>ViewHolder</strong> from the adapter. When the adapter is initiated the ViewModels will be created one by one at the meantime.</p><h3>There are few problems</h3><ol><li>The ViewModels will keep creating until the <strong>fragment</strong>/<strong>activity</strong>’s lifecycle finishes. i.e. there will be unlimited <strong>ViewModels</strong>. It also causes Memory Leak!</li><li>The action’s result in the <strong>ViewModels</strong> will be unexpected.</li><li>If we register some objects in a <strong>ViewModel</strong>, it couldn’t be unregister.</li><li>The items couldn’t be recycled. The reason comes from 1.</li></ol><h3>Let’s solve this critical bug!</h3><p>First, we have to understand the items of the recyclerview are recyclability! The same as the word XD</p><p>That’s why we don’t need to release or unregister them on detach time or some functions. The system(SDK) will help us to finish it. If you really need to do it (as like me).</p><p>My way is that keeping each <strong>ViewModel</strong> to a list container. When the lifecycle of the <strong>activity</strong>/<strong>fragment</strong> which the <strong>RecyclerView</strong> attached is finished, we run all <strong>ViewModels</strong> in the list container to do the detach action.</p><p>My code is as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e99de5048a4505f3e82e302cadfbcd2/href">https://medium.com/media/6e99de5048a4505f3e82e302cadfbcd2/href</a></iframe><p>I google a lot of the articles about how to detach or unregister the ViewHolders, I didn’t find who faces kind of the problem with me, until I found Jake Wharton’s response to a person faces the similar problem in his <strong>RecyclerView</strong>.</p><p>The link is <a href="https://github.com/JakeWharton/butterknife/issues/879">here</a>!</p><p>I just share a method what I could think 😞. If you have any better way to solve similar with this. Please don’t be shy to share to me 🙂</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6c42584a076" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s change the dagger 2 library to 2.11!]]></title>
            <link>https://medium.com/@pokkbaby/i-didnt-post-an-artist-for-a-while-i-was-so-busy-to-do-my-side-project-and-a-little-bit-lazy-948363d16e7f?source=rss-19d9fbedc392------2</link>
            <guid isPermaLink="false">https://medium.com/p/948363d16e7f</guid>
            <dc:creator><![CDATA[Jieyi Wu]]></dc:creator>
            <pubDate>Fri, 01 Dec 2017 23:04:23 GMT</pubDate>
            <atom:updated>2018-01-16T15:55:42.464Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*8jOprJNNHKPQBvZj1e6PfA.jpeg" /></figure><p>The usage of dagger 2 is still changing. Of course we hope our code to be clean, readable and when we code effectively.</p><p>I didn’t post an artist for a while. I was so busy to do my side project and a little bit lazy. 😂</p><p>Dagger 2 I’ve used it in my first side project since two years ago. There are no libraries perfect, Dagger 2 is the same. Because Goggle is modifying them to be better, from 2.11 there are few new features let us simple and clean our code.</p><h3>To resolve the dependency reserve</h3><p>I don’t explain too many reasons why would we use DI tools. That’s not the points this time, I just explain briefly.</p><ul><li>Hardcode constructor</li></ul><p>Assume you understand the reasons here. Let’s go to the main topic!</p><h4>Before dagger 2.10</h4><p>Let’s have glance of dagger 2.10</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/808d1d8ba8370c0185e5372c8cbefa6a/href">https://medium.com/media/808d1d8ba8370c0185e5372c8cbefa6a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a95006630c1fd09ff0f67085ee130970/href">https://medium.com/media/a95006630c1fd09ff0f67085ee130970/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/940488f3658be0fbfc45fa43c717a003/href">https://medium.com/media/940488f3658be0fbfc45fa43c717a003/href</a></iframe><p>Anyway, … There’re so many differences of the usage.</p><h4>After dagger 2.11</h4><p>Google provides the better tools to use this library.</p><ul><li>In the beginning, I’ll show what’s changed in the App component to you for connecting module and the user who needs the objects.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f83bb1cdc0e00cb2387033335e7efdb1/href">https://medium.com/media/f83bb1cdc0e00cb2387033335e7efdb1/href</a></iframe><ul><li>Then you need a provider for providing the objects.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3271945b471ecba04690861b6f0b27c0/href">https://medium.com/media/3271945b471ecba04690861b6f0b27c0/href</a></iframe><ul><li>In common, we shouldn’t use all objects in singleton scope, they should have their own lifetime. Dagger provides scope to us (they have existed before 2.11) for this case.</li></ul><p>Due to the above reason, there is difference way to use it in 2.11.</p><p>For example, the fragment’s lifetime must shorter than activity’s so fragment must be included into activity’s scope. The code will be as like below,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bdc8d82c601d1ccf74680de45c25441/href">https://medium.com/media/4bdc8d82c601d1ccf74680de45c25441/href</a></iframe><p>Here we use the difference scope for the activity and the fragment. Let’s activity include the fragment, the scopes will be set automatically.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/308388113e30d134c370587f390de85b/href">https://medium.com/media/308388113e30d134c370587f390de85b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/951845ae83c7cd33086b74f7cdfd5f52/href">https://medium.com/media/951845ae83c7cd33086b74f7cdfd5f52/href</a></iframe><p>Fragments will use app context sometimes so activity should provide it from app component.</p><h3>Usage</h3><ul><li>The changing in Application,</li><li>The best way in the activity, you can put the injector to base class. As like below,</li><li>Also, you can do the same thing in the base fragment.</li></ul><p>That’s all, it’s simpler than before version 2.11.</p><p>Here is a sample showcase <a href="https://github.com/dev-cloverlab/Kloveroid">GitHub</a> for a basic architecture with dagger 2.11.</p><p>I might really good at using dagger 2.11, welcome to give me a piece advice.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=948363d16e7f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use swatch]]></title>
            <link>https://medium.com/@pokkbaby/how-to-use-swatch-23d477bfd607?source=rss-19d9fbedc392------2</link>
            <guid isPermaLink="false">https://medium.com/p/23d477bfd607</guid>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Jieyi Wu]]></dc:creator>
            <pubDate>Sun, 27 Aug 2017 22:53:28 GMT</pubDate>
            <atom:updated>2018-01-16T15:55:01.179Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
            <content:encoded><![CDATA[<h3>How to use the palette in Android</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*dfrb31keeT0AA1bU4fn0-Q.jpeg" /></figure><p>Sometimes we wanna extract the colors from the image so how can we do?</p><h3>Start</h3><p>Add the library in your app gradle.</p><pre>compile &#39;com.android.support:palette-v7:25.1.0&#39;</pre><p>We have four ways to create the palette.</p><pre>// Now Palette.from(bitmap) is the same as Palette.Builder(bitmap).<br><br>// Synchronous methods.<br>// --------------------------------<br>// These should be used when you have access to the underlying image loading thread.<br>// Picasso allows this through a Transformation. For other libraries, YMMV.<br>// Uses the default palette size (16).<br>Palette p = Palette.from(bitmap).generate();<br>// Allows you to specify the maximum palette size, in this case 24.<br>Palette p = Palette.from(bitmap).maximumColorCount(24).generate();<br><br>// Asynchronous methods<br>// --------------------------------<br>// This is the quick and easy integration path. Internally uses an AsyncTask so<br>// this may not be optimal (since you&#39;re dipping in and out of threads)<br>// Uses the default palette size (16).<br>Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {<br>    @Override<br>    public void onGenerated(Palette palette) {<br>       // Here&#39;s your generated palette<br>    }<br>});<br>// Allows you to specify the maximum palette size, in this case 24.<br>Palette.from(bitmap).maximumColorCount(24).generate(new Palette.PaletteAsyncListener() {<br>    @Override<br>    public void onGenerated(Palette palette) {<br>       // Here&#39;s your generated palette<br>    }<br>});</pre><h3>Six swatchs</h3><p>We often use <strong>Vibrant</strong> and <strong>Dark Vibrant</strong>.</p><pre>// Vibrant.<br>Palette.getVibrantSwatch()<br>// Vibrant dark.<br>Palette.getDarkVibrantSwatch()<br>// Vibrant light.<br>Palette.getLightVibrantSwatch()<br>// Muted.<br>Palette.getMutedSwatch()<br>// Muted dark.<br>Palette.getDarkMutedSwatch()<br>// Muted light.<br>Palette.getLightMutedSwatch()</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23d477bfd607" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[First side project about Movie]]></title>
            <link>https://medium.com/@pokkbaby/first-side-project-about-movie-30a1e75b68e2?source=rss-19d9fbedc392------2</link>
            <guid isPermaLink="false">https://medium.com/p/30a1e75b68e2</guid>
            <category><![CDATA[mvp]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[movies]]></category>
            <dc:creator><![CDATA[Jieyi Wu]]></dc:creator>
            <pubDate>Tue, 11 Jul 2017 11:00:55 GMT</pubDate>
            <atom:updated>2017-07-11T11:00:55.095Z</atom:updated>
            <content:encoded><![CDATA[<p>Due to I was busy in my side project &amp; studying new things, it’s long time I didn’t write an article.</p><p>This time I wanna share my practice to you. It’s an Android app about introducing the movies, the dramas, and actresses &amp; actors. For enhancing my skills &amp; abilities, I decided to develop an app about Movie(actually I just only knew the movie API is supported XD).</p><p>There are so many picture need to download from the remote server, that’s a challenge to handle the memory and avoid the OOM. The biggest challenge is making a custom view by myself. Although this time I made few custom views by myself. Most of them was used by others third party libraries. This is first time to make an app so spend a lot of time to choose the libraries and learn how to use them.</p><p>This is not perfect but enough to learn basic skills. Next I’m preparing a music app, it has deeper knowledge to achieve it. For example: Custom view, architecture, database, …….</p><p><strong>One more thing</strong></p><p>Only you really do it by yourself no matter what it’s like a nothing. The knowledge will become a part of you. Just only read others people blogs or articles, of course it’s good, but most of time it’s not easy acquire knowledge what you read.</p><p>Let’s dirty our hand, together!</p><p>The repo link is here: <a href="https://github.com/pokk/mvp-magazine">https://github.com/pokk/mvp-magazine</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30a1e75b68e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android’s hashmap optimization]]></title>
            <link>https://medium.com/@pokkbaby/androids-hashmap-optimization-30a1d054efec?source=rss-19d9fbedc392------2</link>
            <guid isPermaLink="false">https://medium.com/p/30a1d054efec</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Jieyi Wu]]></dc:creator>
            <pubDate>Thu, 23 Feb 2017 03:11:56 GMT</pubDate>
            <atom:updated>2017-12-03T03:09:38.955Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*qw4C8cc8R6JlsCa4S9ZVmQ.jpeg" /></figure><p>Optimize the Android’s memory usage by using <strong><em>SparseArray</em></strong> and <strong><em>ArrayMap</em></strong> to instead of <strong>HashMap</strong>.</p><p>HashMap’s default capacity is <em>16</em> for keeping the data. Inside of the data struct we will explain as below.</p><h3>Data struct of HashMap</h3><p>I think everyone know this HashMap’s data struct as well. The data struct is as below.</p><pre>Entry 0 --&gt; Entry --&gt; Entry <br>Entry 1 --&gt; Entry <br>Entry 2 --&gt; Entry --&gt; Entry <br>Entry 3 --&gt; Entry --&gt; Entry --&gt; Entry <br>Entry 4 --&gt; Entry --&gt; Entry<br>   .<br>   .<br>   . <br>Entry n-1 --&gt; Entry --&gt; Entry --&gt; Entry <br>Entry n --&gt; Entry</pre><h4>Inside of Entry’s variables</h4><pre>final K key;<br>V value; <br>final int hash; <br>HashMapEntry&lt;K, V&gt; next;</pre><p>According to the variables of the HashMap, the next of Entry’s data is still an Entry data struct. The hash value is calculated by the key. So we can know if the result of the key hashed is always the same value, the specific Entry’s link will be long, cause wasting the memory and the redundant operation of allocate and free.</p><p>More detail, if the capacity is full so the mechanism is that HashMap’s space will be double. Suppose to there are a billion data. HashMap will keep all of them then HashMap will make enough space many times and calculate the hash code of each single data.</p><p>As a result, there are huge data let system become slow. In normal situation, it’s better to use <strong><em>SparseArray</em></strong> or <strong><em>ArrayMap</em></strong> instead <em>HashMap</em>.</p><h3>SparseArray</h3><p>Using SparseArray is more saving memory usage than using HashMap. <br>After see the variables of inside of SparseArray, we can know why SparseArray is better in some situations.</p><h4>SparseArray Variable</h4><pre>private int[] mKeys;<br>private Object[] mValues;</pre><h4>The way of the mechanism of putting and getting</h4><pre>public void put(int key, E value) {<br>    int i = ContainerHelpers.binarySearch(mKeys, mSize, key);<br>    ...<br>}</pre><pre>public E get(int key, E valueIfKeyNotFound) {<br>    int i = ContainerHelpers.binarySearch(mKeys, mSize, key);<br>    ...<br>}</pre><p>In the SparseArray, it just uses Integer type for keeping the key value. And it’s using <strong><em>binary search</em></strong> for putting and getting a data. <br>Because the operation of the SparseArray is using <strong><em>binary search</em></strong>, the searching speed is faster than HashMap. <br>Time complexity of the worst case of HashMap is <strong>O(N)</strong>, SparseArray is <strong>O(logN)</strong>.</p><h4>Using Scenario of SparseArray</h4><ul><li>The amount of data is less than thousand.</li><li>The data type of key must be Integer.</li></ul><h3>ArrayMap</h3><p>It’s designed for optimizing the memory usage. The data type of ArrayMap is a . The operations’ mechanism of Put and Get are the same as SparseArray. So the using scenario is total same as SparseArray.</p><h4>Using Scenario of ArrayMap</h4><ul><li>The amount of data is less than thousand.</li><li>The data type is Map.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30a1d054efec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Http Transport Security Problem]]></title>
            <link>https://medium.com/@pokkbaby/http-transport-security-problem-cf3cc4de2083?source=rss-19d9fbedc392------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf3cc4de2083</guid>
            <dc:creator><![CDATA[Jieyi Wu]]></dc:creator>
            <pubDate>Wed, 04 Jan 2017 02:06:50 GMT</pubDate>
            <atom:updated>2017-01-04T02:06:50.590Z</atom:updated>
            <content:encoded><![CDATA[<p>First time I used a WebView for showing a web site. After I finished a simple iOS application and run it. Nothing was showed on the WebView!! It’s just a white default view, just NOTHING.</p><p>Because I was a beginner, I didn’t figure out debug message where was showed. Finally, I found a message.</p><blockquote><strong><em>Error Message:</em></strong><em><br></em><strong><em>Application Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file.</em></strong></blockquote><p>I found a solution for me is that:</p><blockquote><strong><em>Solution:</em></strong><em><br> 1. I open the </em><strong><em>info.plist</em></strong><em>.</em></blockquote><blockquote><em>2. </em><strong><em>Right-click</em></strong><em> and </em><strong><em>Add row</em></strong><em>.</em></blockquote><blockquote><em>3. Key </em><strong><em>App Transport Security Settings</em></strong><em> , Type </em><strong><em>Dict</em></strong><em>.</em></blockquote><blockquote><em>4. Then add a row again as a item.</em></blockquote><blockquote><em>5. Key </em><strong><em>NSAllowsArbitraryLoads</em></strong><em>, Type </em><strong><em>Boolean</em></strong><em>, Value </em><strong><em>True</em></strong><em>.</em></blockquote><p>Or you just add as below in <strong>info.plist</strong>.</p><pre>&lt;key&gt;NSAppTransportSecurity&lt;/key&gt; &lt;dict&gt; &lt;key&gt;NSAllowsArbitraryLoads&lt;/key&gt;&lt;true/&gt; &lt;/dict&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf3cc4de2083" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Customize View in Android]]></title>
            <link>https://medium.com/@pokkbaby/customize-view-in-android-86491cf5492?source=rss-19d9fbedc392------2</link>
            <guid isPermaLink="false">https://medium.com/p/86491cf5492</guid>
            <category><![CDATA[views]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Jieyi Wu]]></dc:creator>
            <pubDate>Sun, 25 Dec 2016 07:09:57 GMT</pubDate>
            <atom:updated>2016-12-25T07:09:57.837Z</atom:updated>
            <content:encoded><![CDATA[<p>Customize View by yourself, you must inherit View class. For the View class, it must run this three methods in flow. Brief describe as below</p><ol><li><strong>onMeasure()</strong>: Set the layout <em>size</em>.</li><li><strong>onLayout()</strong>: Set the layout <em>position</em>.</li><li><strong>onDraw()</strong>: Draw the <em>layout content</em>.</li></ol><p>Before the flow, I will explain a little the constructor of View or ViewGroup. Normally, there are three constructor we need to override.</p><ol><li><strong>public View (Context context): </strong>It will be used in Java code when you code new Customize(context).</li><li><strong>public View (Context context, AttributeSet attrs): </strong>When you set some <strong>attributes</strong> in xml layout and don’t set <strong>Style</strong>.</li><li><strong>public View (Context context, AttributeSet attrs, int defStyle): </strong>Base on the 2 and set the <strong>Style</strong>.</li></ol><p>So if don’t use <strong>Style</strong>, we can just only focus on public View (Context context, AttributeSet attrs).</p><p>There’re three main methods of Measure class.</p><ol><li><strong>getMode(int measureSpec)</strong>: It can obtain the spec mode from measureSpec.</li><li><strong>getSize(int measureSpec)</strong>: It can obtain the spec size from measureSpec.</li><li><strong>makeMeasureSpec(int size, int mode)</strong>: According to the size and the mode to create a new measureSpec.</li></ol><p>Here are three type of mode:</p><ol><li><strong>UNSPECIFIED</strong>: Parent’s View doesn’t force the constraint of Children’s View. They can be any size.</li><li><strong>EXACTLY</strong>: Parent’s View has already confirmed Children’s View exactly. Children will be constrained and their settings of the size will be ignored.</li><li><strong>AT_MOST</strong>: The size of children’s View cannot over set from assigned size.</li></ol><p>Actually, onMeasure(widthMeasure, heightMeasure) of two parameters are that an integer number of combing from <em>mode</em> and <em>size</em> , you have to get the mode or the size from MeasureSpec.getMode or MeasureSpec.getSize for getting Parent&#39;s parameters.</p><p>So the size of the view will be effected by three aspects.</p><ol><li>The MeasureSpec of Parent’s View.</li><li>The LayoutParams of Children’s View.</li><li>setMeasuredDimension() or the methods of set mMeasuredWidth, mMeasuredHeight.</li></ol><p>Each of view includes ViewGroup.LayoutParams class or delegate class and LayoutParams show The relationship between View and Parents’s View. The size of view is decided by View and Parent’s View.</p><p>Normally, when we want to add a view to <strong>RelativeLayout</strong> or <strong>LinearLayout</strong>, no matter by addView or write in xml layout file, onMeasure() will be called automatically. And the two parameters of onMeasure are from Parent&#39;s View.</p><p>Of course we can set the value of width and height directly in xml layout file or match_parent/wrap_content, we can also set LayoutParams in the code. The settings will correspond to the parameters of onMeasure method.</p><p>For example,</p><ul><li>Set a value(width=200dp) or match_parent/fill_parent in xml or LayoutParams. Mode is <strong>MeasureSpec.EXACTLY</strong>.</li><li>Set (width=wrap_content). Mode is <strong>MeasureSpec.AT_MOST</strong>. Here is a table of heightMeasureSpec or widthMeasureSpec from Parent to Children when the system calls measure() method.</li></ul><p>Parent’s View MeasureSpec Child’s View LayoutParams Child’s View invalidate()</p><p>We often use this method. It will help us to request to redraw(draw()) the tree of View. If views don&#39;t change the size then layout() won&#39;t be called.</p><ol><li><strong>invalidate()</strong>: Request a redraw and draw() will be called, but only caller will do draw().</li><li><strong>setSelection()</strong>: Request a redraw and draw() will be called, but only caller will do draw().</li><li><strong>setVisibility()</strong>: Switch INVISIBLE to VISIBLE, invalidate() will be called indirectly.</li><li><strong>setEnabled()</strong>: Request a redraw and draw() will be called.</li></ol><h3>requestLayout()</h3><p>It will cause that measure() and layout() run. This is for re-layout the tree of Views, so it&#39;s not including draw() method.</p><h3>Adaptive ImageView</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/129f763bee8868a44cc1630af1328472/href">https://medium.com/media/129f763bee8868a44cc1630af1328472/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86491cf5492" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python — List to Dict]]></title>
            <link>https://medium.com/@pokkbaby/python-list-to-dict-7c161faf4937?source=rss-19d9fbedc392------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c161faf4937</guid>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Jieyi Wu]]></dc:creator>
            <pubDate>Sun, 25 Dec 2016 06:49:32 GMT</pubDate>
            <atom:updated>2016-12-25T06:49:32.731Z</atom:updated>
            <content:encoded><![CDATA[<p>If you wanna change <strong><em>list</em></strong> to <strong><em>dict</em></strong>, it’s a conveient way here.</p><pre>import collections<br>arr = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;]<br>dic = collections.defaultdict.fromkeys(arr, None)</pre><pre>result&gt;&gt;&gt; {&#39;b&#39;: None, &#39;e&#39;: None, &#39;a&#39;: None, &#39;c&#39;: None, &#39;d&#39;: None}</pre><p>Of course you can use list comprehension in function.</p><pre>import collections<br>dic = collections.defaultdict.fromkeys([num for num in range(5)], None)</pre><pre>result&gt;&gt;&gt; {&#39;0&#39;: None, &#39;1&#39;: None, &#39;2&#39;: None, &#39;3&#39;: None, &#39;4&#39;: None}</pre><p>This is better than dict() to do something operate. Also, you can serach <a href="http://t.umblr.com/redirect?z=https%3A%2F%2Fdocs.python.org%2F3%2Flibrary%2Fcollections.html%23module-collections&amp;t=MmY1ZGFmYWFlYzk1NjM5ZTU0ZTllNGNiOGY4MGI1NDFiMjU5OWE5YixRRk00WWNudg%3D%3D&amp;b=t%3AlMJKGPLqh1ZEqaFDtB82sg&amp;p=http%3A%2F%2Fjieyiwu.tumblr.com%2Fpost%2F140382922445%2Fpython-list-to-dict&amp;m=1">Python Collections</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c161faf4937" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>