<?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 Orhan Obut on Medium]]></title>
        <description><![CDATA[Stories by Orhan Obut on Medium]]></description>
        <link>https://medium.com/@orhanobut?source=rss-fbe7407255e5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*frXSRe2HjhPQfmlPF6iybA.jpeg</url>
            <title>Stories by Orhan Obut on Medium</title>
            <link>https://medium.com/@orhanobut?source=rss-fbe7407255e5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 20:40:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@orhanobut/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[Android 101: Gradle dependencies]]></title>
            <link>https://medium.com/android-news/android-101-gradle-dependencies-9e2742b59f9?source=rss-fbe7407255e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e2742b59f9</guid>
            <category><![CDATA[dependencies]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Orhan Obut]]></dc:creator>
            <pubDate>Thu, 08 Feb 2018 10:11:07 GMT</pubDate>
            <atom:updated>2018-03-08T00:52:40.233Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*doVVynSGmJo1-C7iIj_CUg.png" /></figure><p>In Gradle, dependencies are declared as closure in dependencies block.</p><pre>dependencies {<br>   implementation &#39;com.squareup.okhttp3.okhttp:3.9.1`<br>}</pre><p>Dependency tree can be displayed via ./gradlew dependencies task. This will display all direct and transitive dependencies.</p><pre>+--- <strong>com.squareup.okhttp3:okhttp:3.9.1       : Direct artifact</strong><br>     \--- com.squareup.okio:okio:1.6.0      : Transitive dependency</pre><h4>Packaging type</h4><p>All artifacts have a packaging type e.g. <strong>jar</strong>, <strong>aar. </strong>Author of the artifact could specify the default packaging type in POM before publishing. If it is not specified in POM, then the default type will be <strong>jar </strong>for downloading.</p><p><strong>Jar (Java Archive):</strong> A packaging file format that is used to aggregate and zip java class files.</p><p><strong>Aar (Android Archive):</strong> Same as jar, additionally includes android resources such as layouts, drawables and AndroidManifest file.</p><h4>Downloading an artifact with the default packaging type (Recommended)</h4><p>If the packaging type is not specified explicitly when declaring dependency as the example below, artifacts will be downloaded with the default packaging type that’s specified in POM file.</p><pre>dependencies {<br>   implementation &quot;com.squareup.okhttp3:okhttp:3.9.1&quot;<br>   implementation &quot;com.android.support:percent:26.0.0&quot;<br>}</pre><p>Gradle will download the artifacts for okhttp as jar and for percent as aar. Author of percent declared the packacing type as aar in POM file, therefore Gradle will use this default packaging type to download the artifact.</p><pre>+--- <strong>com.squareup.okhttp3:okhttp:3.9.1</strong><br>|    \--- com.squareup.okio:okio:1.6.0<br>\--- <strong>com.android.support:percent:26.0.0</strong><br>     \--- com.android.support:support-compat:26.0.0<br>          \--- com.android.support:support-annotations:26.0.0</pre><h4>Downloading an artifact by specifying packaging type</h4><p>Packaging type can be explicitly specified by appending @type notation.</p><pre>dependencies {<br>    implementation &quot;com.squareup.okhttp3:okhttp:3.9.1<strong>@jar</strong>&quot;<br>    implementation &quot;com.android.support:percent:26.0.0<strong>@aar</strong>&quot;<br>}</pre><p>Artifacts are downloaded as jar for “okhttp and as aar for “percent”.</p><pre>+--- com.squareup.okhttp3:okhttp:3.9.1<br>\--- com.android.support:percent:26.0.0</pre><p>But the dependency tree is slightly different now, as a result transitive dependencies are not downloaded. Gradle downloads only the main artifact without transitive dependencies when this notation is used. It is also called <strong>artifact-only notation.</strong></p><p>There are a few ways to resolve this issue:</p><ul><li>Using transitive=true and explicitly tell Gradle to download the transitive dependencies.</li></ul><pre>dependencies {<br>    implementation(&quot;com.squareup.okhttp3:okhttp:3.9.1@jar&quot;) {<br>        <strong>transitive true</strong><br>    }   <br>    implementation(&quot;com.android.support:percent:26.0.0@aar&quot;){<br>        <strong>transitive true</strong><br>    }<br>}</pre><ul><li>Gradle will resolve the issue automatically if another direct/indirect dependency have the same transitive dependencies.</li></ul><p>For example, missing dependencies for percent will be resolved through recyclerview-v7 automatically.</p><pre>dependencies {<br>    implementation(&quot;com.android.support:percent:26.0.0<strong>@aar</strong>&quot;)<br>    implementation &quot;com.android.support:recyclerview-v7:26.0.0&quot;<br>}</pre><ul><li>Each missing dependency is declared explicitly one by one.</li></ul><pre>dependencies {<br>    implementation(&quot;com.squareup.okhttp3:okhttp:3.9.1@jar&quot;)  <br>    implementation(&quot;com.android.support:percent:26.0.0@aar&quot;)<br>    <br>    // transitive dependencies are declared one by one</pre><pre>    implementation &quot;com.squareup.okio:okio:1.6.0&quot;<br>    implementation &quot;com.android.support:support-compat:26.0.0&quot;<br>}</pre><h4>What if there is no artifact with the given packaging type?</h4><p>Gradle will try to download the artifact but ultimately it’ll fail because it doesn’t exist in the repository for the specified packaging type.</p><pre>dependencies {<br>    implementation &quot;com.squareup.okhttp3:okhttp:3.9.1<strong>@aar</strong>&quot;<br>}</pre><p>Output with error:</p><pre>Failed to resolve: okhttp</pre><h4>Excluding specific transitive dependencies</h4><p>Specific transitive dependencies can be excluded as in the situation of conflict.</p><p>Following example shows how to remove support-annotations transitive dependency from percent library.</p><pre>dependencies {<br>  implementation(&quot;com.android.support:percent:26.0.0&quot;) {<br>    <strong>exclude group:&#39;com.android.support&#39;,module:&#39;support-annotations&#39;</strong><br>  }<br>}</pre><p><strong>group</strong> can be omitted if module is unique</p><pre>dependencies {<br>  implementation(&quot;com.android.support:percent:26.0.0&quot;) {<br>    <strong>exclude module:&#39;support-annotations&#39;</strong><br>  }<br>}</pre><p>Observe that support-annotations no longer exists in the dependency tree.</p><pre>+--- <strong>com.android.support:percent:26.0.0</strong><br>     \--- com.android.support:support-compat:26.0.0</pre><h4><strong>Transitive dependency resolution strategy</strong></h4><p>Different artifact versions might be declared at the same time. Gradle will try to resolve it by choosing the latest version.</p><p>In the following example, a newer version of support-annotations is declared explicitly. percent also has the same dependency with an older version implicitly.</p><pre>dependencies { <br>    implementation &quot;com.android.support:support-annotations:<strong>27.0.2</strong>&quot;<br>    implementation &quot;com.android.support:percent:26.0.0&quot;<br>}</pre><p>Observe that transitive dependency indicates the latest version.</p><pre>+-- <strong>com.android.support:support-annotations:27.0.2</strong><br>\-- <strong>com.android.support:percent:26.0.0</strong><br>    \-- com.android.support:support-compat:26.0.0<br>        \-- <em>com.android.support:support-annotations:26.0.0 -&gt; 27.0.2</em></pre><p><strong>What happens if the version has qualifier such as 26.0.0 vs 26.0.0-alpha?</strong></p><p>I did some testing and it seems Gradle also uses the same version comparison as maven. For the complete list of how version ordering works, check <a href="https://maven.apache.org/pom.html#Version_Order_Specification">maven version order specification</a>.</p><h4>Links</h4><ul><li><a href="https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jarGuide.html">Jar file overview</a></li><li><a href="https://developer.android.com/studio/projects/android-library.html#aar-contents">Aar file overview</a></li><li><a href="https://maven.apache.org/guides/introduction/introduction-to-the-pom.html">Introduction to POM</a></li><li><a href="https://maven.apache.org/pom.html#Version_Order_Specification">Maven version order specification</a></li></ul><h4>More Android 101</h4><ul><li><a href="https://medium.com/@orhanobut/android-and-typography-101-5f06722dd611">Android 101: Typography</a></li><li><a href="https://medium.com/@orhanobut/shared-preferences-101-aee26c13e4">Android 101: Shared Preferences</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e491f%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F3e491f%2F&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252F3e491f%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href">https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e2742b59f9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/android-101-gradle-dependencies-9e2742b59f9">Android 101: Gradle dependencies</a> was originally published in <a href="https://medium.com/android-news">AndroidPub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android 101: Shared Preferences]]></title>
            <link>https://proandroiddev.com/shared-preferences-101-aee26c13e4?source=rss-fbe7407255e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/aee26c13e4</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[sharedpreferences]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Orhan Obut]]></dc:creator>
            <pubDate>Thu, 04 Jan 2018 07:42:46 GMT</pubDate>
            <atom:updated>2018-03-06T08:15:13.396Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nlTmfDWNF5GoF_gLQVjetg.png" /></figure><p>Shared preferences is a built-in key-value storage.</p><p>Following code retrieves the single instance of shared preferences for the given name. The <strong>same</strong> <strong>instance</strong> is used across the application whenever it’s retrieved.</p><pre>val pref = getSharedPreferences(&quot;PREF&quot;, <em>MODE_PRIVATE</em>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*La5k3FLl48fZXl1Ro8jCJA.png" /><figcaption>Retrieves shared preferences instance for the name “PREF”.</figcaption></figure><p>Each shared preferences will have its own instance based on the preference name.</p><pre>val pref2 = getSharedPreferences(&quot;PREF2&quot;, <em>MODE_PRIVATE</em>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cBstCAJJQhkCQeF4oKjCNQ.png" /><figcaption>Notice that pref and pref2 have their own instance because of the different names</figcaption></figure><p>No matter in which context (Activity, fragment, application) it’s called, it’ll always return the same instance for the same name. This guarantees that you will always see the latest changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*55Ywb_zdKBgK6PhZSnW2iA.png" /><figcaption>Notice that pref2 and pref3 uses the same instance because of the same name</figcaption></figure><h4>Shared preferences internal structure</h4><p>Shared preferences internally has an in-memory storage on top of disk storage. Every operation goes through in-memory storage first and then to the disk if necessary.</p><ul><li>In-memory storage is basically a HashMap which allows O(1) runtime complexity for all operations.</li></ul><pre>val map = HashMap&lt;String, Any&gt;()</pre><ul><li>Disk storage is an xml file which is structured as</li></ul><pre>&lt;?xml version=&#39;1.0&#39; encoding=&#39;utf-8&#39; standalone=&#39;yes&#39; ?&gt;<br>&lt;map&gt;<br>    &lt;string name=&quot;KEY&quot;&gt;value&lt;/string&gt;<br>&lt;/map&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RKU4stnFp9IP0cTwoucndg.png" /></figure><h4>Get the data</h4><p>All get operations are done through <strong>in-memory storage</strong>, which is immediate and IO operation is avoided. Since all operations go through in-memory first, this is guaranteed to return the latest value.</p><pre>val value = pref.getString(key, null)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VpI55wxtdx3cag7lr8ijvA.png" /></figure><p><em>Note that if it’s the first time loading, it’ll wait until all data is loaded to in-memory storage from disk.</em></p><h4>Save data via commit.</h4><p>Saves the data to in-memory storage first and then <strong>synchronously</strong> writes it to disk. Since IO operation is involved, main thread is blocked until the data is written to the disk. This is an expensive operation in comparison to apply</p><blockquote>Since the disk write operation is synchronous, success status is returned as a boolean. Therefore, you can verify that whether the operation is successful or not by checking the return value.</blockquote><pre>val result = pref.edit().putString(key, &quot;value&quot;).commit()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rO0nXiTXCJcQSABMMDWC7Q.png" /><figcaption>Put a string to shared preferences by using commit</figcaption></figure><h4>Save data via apply.</h4><p>Saves the data to in-memory storage first and then <strong>asynchronously</strong> writes it to disk. Main thread is not blocked and waiting for the disk operation anymore. Any read (get) after apply will return the latest saved value because of get operations are done through in-memory storage.</p><blockquote>Since the disk write operation is asynchronous there is no return value as status. Therefore, you cannot verify that whether the operation is successful or not.</blockquote><blockquote>Use &quot;apply&quot; unless you need to verify the operation result.</blockquote><pre>pref.edit().putString(key, &quot;value&quot;).apply()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ehdwZl3wk6l7_mPR5G47lg.png" /><figcaption>Put a string to shared preferences by using apply</figcaption></figure><h4>Other operations</h4><p>Apart from put and get, shared preferences also provides the following operations:</p><ul><li>Check if any key exists</li><li>Observe shared preferences changes via listener</li><li>Get all entries as map</li><li>Remove a specific entry</li><li>Clear all</li></ul><h3>Bonus</h3><ul><li>Application scoped shared preferences are stored under:</li></ul><pre>data/data/&lt;YOUR_APP_ID&gt;/shared_prefs/&lt;SHARED_PREF_NAME&gt;.xml</pre><ul><li>You can use Device File Explorer in Android Studio to check them.</li></ul><h4>More Android 101</h4><ul><li><a href="https://medium.com/@orhanobut/android-and-typography-101-5f06722dd611">Android 101: Typography</a></li><li><a href="https://medium.com/@orhanobut/android-101-gradle-dependencies-9e2742b59f9">Android 101: Gradle Dependencies</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aee26c13e4" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/shared-preferences-101-aee26c13e4">Android 101: Shared Preferences</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android 101: Typography]]></title>
            <link>https://proandroiddev.com/android-and-typography-101-5f06722dd611?source=rss-fbe7407255e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f06722dd611</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[typography]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[text]]></category>
            <dc:creator><![CDATA[Orhan Obut]]></dc:creator>
            <pubDate>Fri, 15 Sep 2017 12:18:48 GMT</pubDate>
            <atom:updated>2018-06-28T12:52:26.603Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*b0hOP-3kHuxi5MkBzJ3s8w.png" /></figure><p>One way or another, every developer involves with text and some of us has to go deeper to create some custom drawings. In order to make it right and proper, some terms about text and how the framework provides it, needs to be known.</p><p>First and foremost, let’s start with some terms:</p><p><strong>Typography </strong>is the visual aspect of the text. It uses art and techniques to make the distinction between the same texts.</p><pre>The word &quot;typography&quot; in English comes from the <a href="https://en.wikipedia.org/wiki/Greek_language">Greek</a> roots τύπος <em>typos</em> = &quot;impression&quot; and -γραφία <em>-graphia</em> = &quot;writing&quot;. <br>                                                         <strong>Wikipedia</strong></pre><p><strong>Font </strong>is a specific visual representation of the text. For example: Times New Roman.</p><p><strong>Typeface (Font Family) </strong>is the set of different variations of the same font. For example: Times New Roman Regular, Times New Roman Bold and Times New Roman Italic etc. The characteristics design of the font doesn’t change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*Oj0jZL3Qt9EgyMHBiippMQ.png" /></figure><p><strong><em>Glyph </em></strong>is the visual<em> </em>representation of a single character. ie: a B ; .</p><h3>Font metrics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v1FDlH-vFEnhXDFDxp6OXg.png" /></figure><p><strong>Top:</strong> The maximum distance above the baseline for the tallest glyph in the font at a given text size. Top line is usually further in comparison to bottom line due to non-ascii characters. e.g. Á character</p><p><strong>Ascent:</strong> The recommended distance above the baseline for singled spaced text. Ascent line is usually further in comparison to descent line due to non-ascii characters.</p><p><strong>Mean line: </strong>The top line for the letters that doesn’t have ascending.</p><p><strong>Baseline:</strong> This is the line each letters sit upon.</p><p><strong>Descent: </strong>The recommended distance below the baseline for singled spaced text.</p><p><strong>Bottom:</strong> The maximum distance below the baseline for the lowest glyph in the font at a given text size.</p><p><strong>Leading:</strong> The space between the lines, basically the space between bottom of the line and top of the next line.</p><p><strong>Line height: </strong>The distance between bottom and top.</p><h3>How to get metrics</h3><h4><a href="https://developer.android.com/reference/android/graphics/Paint.FontMetrics.html">Font Metrics</a></h4><p>Whenever something is drawn, a paint object is always passed through. It holds color and style information about how to draw. Style holds the typeface information. You can get “ascent, descent, top, bottom, leading” metrics from FontMetrics object for the given font.</p><pre>Paint paint = new Paint();<br>FontMetrics metrics = paint.getFontMetrics();</pre><p>Note that font metric values are relative, you need to use baseline to get exact position for canvas. For instance: In order to get exact y position for ascent for the given canvas, you need to use baseline.</p><pre>baseline + metrics.ascent -&gt; Actual y position on the canvas</pre><h4><a href="https://developer.android.com/reference/android/graphics/Paint.html#getTextBounds(java.lang.String,%20int,%20int,%20android.graphics.Rect)">Paint.getTextBounds()</a></h4><p>Returns the bounds the smallest rectangle that encloses all of the characters, with an implied origin at (0,0)<em>. </em>Note that, Y values are the opposite of what you would think. Going down is increasing the value and going up to ascent is decreasing.</p><pre>Rect bounds = new Rect();<br>Paint paint = new Paint();<br>String text = &quot;These&quot;;<br>paint.getTextBounds(text, 0, text.length, bounds);</pre><p>One common mistake would be to assume that once you measure the height for a part of the text, it’ll be the same for the remaining. As you see the below, enclosed boundaries may have different size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qxPY7h_otXU0WyesECs8yg.png" /><figcaption>I used the opposite sign for Y values to represent the bounds simplier</figcaption></figure><h4><a href="https://developer.android.com/reference/android/graphics/Paint.html#measureText(char[],%20int,%20int)">Paint.measureText()</a></h4><p>Measures the width of the text by considering the glyph. The width might be different than getTextBounds, but this value is more accurate. Glyph might have some advancement space, hence there is width differences.</p><pre>Paint paint = new Paint();<br>String text = &quot;This&quot;;<br>paint.measureText(text, 0, text.length);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yyk9u3mnk88jjYsBQlSuuQ.png" /></figure><p>In order to get an accurate width, you can use Paint.measureText Combine both measureText and getTextBounds in order to get accurate values for both height and width.</p><h4><a href="https://developer.android.com/reference/android/text/StaticLayout.html">StaticLayout</a></h4><p>Note that above solutions only work for the standard text and single line. If you want to measure any Spannable or work with multiple lines, consider StaticLayout. As the name indicates, static layout won’t be changed after it is laid out.</p><blockquote>When you convert <em>Spannable</em> to <em>String</em> (ie: .toString), you loose all your spans. You can’t use Spannable in Paint.getTextBounds or Paint.measureText That’s one of the reason you may want to consider StaticLayout</blockquote><pre>Spannable spannable = new SpannableString(&quot;This&quot;);<br>spannable.setSpan(new RelativeSizeSpan(3), 0, 1, SPAN_EXCL_EXCL);</pre><pre>TextPaint paint = new TextPaint();<br>StaticLayout layout = StaticLayout.Builder<br>    .<em>obtain</em>(spannable, 0, text.length(), paint, 1000)<br>    .build();</pre><pre>float width = layout.getLineWidth(0);    // 36</pre><h4>More options</h4><p>There are a few other options to measure the text size in different cases. For instance, if the text changes dynamically, you can use <a href="https://developer.android.com/reference/android/text/DynamicLayout.html">DynamicLayout</a> which updates itself when the text changes. Or there is <a href="https://developer.android.com/reference/android/text/BoringLayout.html">BoringLayout</a> which I never used before.</p><h3>Some more information about typography</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_p7MCrcL8ENeTLiHhwlB6Q.png" /></figure><p><strong>Serif:</strong> It’s the ending part in the red rectangle.</p><p><strong>Sans Serif: </strong>Sans means “without”, sans serif =font without serif.</p><p><strong>Tracking:</strong> The space between the characters.</p><p><strong>Kerning:</strong> The space between individual characters to provide a pleasant look. Notice that how V and A are close to each other and how weird it’d look if there was no adjustment.</p><h4>More Android 101</h4><ul><li><a href="https://medium.com/@orhanobut/shared-preferences-101-aee26c13e4">Android 101: Shared Preferences</a></li><li><a href="https://medium.com/@orhanobut/android-101-gradle-dependencies-9e2742b59f9">Android 101: Gradle Dependencies</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f06722dd611" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/android-and-typography-101-5f06722dd611">Android 101: Typography</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code review should be fun]]></title>
            <link>https://medium.com/@orhanobut/code-review-should-be-fun-fcaa3b1d12b0?source=rss-fbe7407255e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcaa3b1d12b0</guid>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Orhan Obut]]></dc:creator>
            <pubDate>Wed, 07 Sep 2016 12:43:02 GMT</pubDate>
            <atom:updated>2016-09-10T08:33:41.859Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>We all love code reviews, we love that someone sits in front of the computer and add a lot of comments for our code.</blockquote><blockquote>- Developer</blockquote><p>I think this is the most common lie we tell ourselves. The reason is that many developers are emotional and human beings don’t like being criticized. Even though everyone says “Yeah I love it”.</p><p>There are a couple of reasons that we don’t follow this kind of code review:</p><ul><li>Your pull request has to wait until someone picks it up. Even If you assign it to someone by force, they won’t do it any time soon. There is a waiting time, because they can.</li><li>Reviewer first needs to understand the context, then needs to check every single line. Assume that the pull request contains some new techniques or approaches that reviewer doesn’t know. A usual symptom is that reviewers don’t ask questions and try to understand everything by himself/herself instead. Therefore reviewer would try to check on the internet and try to learn the same things. Duplicated learning process.</li><li>Back and forth comment wars. After a while, comments contain paragraphs, scientific articles etc.</li><li>Reviewer might not actually give enough attention and could just say “Looks super awesome to me”.</li><li>It is super difficult to express yourself with words, therefore comments might create tension. Some people try to make nicer comments by adding a lot of nice words (could you, please, I would do if I was), some people are straight-forward (remove this!)</li><li>Some people are afraid to write comments because they think they will hurt developer feelings or they just don’t want to discuss</li><li>Some people are not sure about how to ask a question or worse they think some people would think less of them if they ask something they didn’t understand very well.</li><li>All of above becomes a huge friction for productivity and no longer fun.</li></ul><h3>How to make it fun and educational for both developer and reviewer?</h3><p>We use pair programming for our advantage. Instead of sitting alone in front of his/her computer and writing comments, both reviewer and developer sit together and developer starts presenting what he/she did first. Developer explains what he/she learned during the process and share the knowledge. Both parties ask questions to each other.</p><p>Since they do this process together, there is almost no tension. People are more calm when they are next to each other. It’s more easy to express yourself properly. It’s more easy to ask questions.</p><p>Step by step how we do it :</p><ul><li>Developer creates a pull request.</li><li>Developer checks any available person who can make a review. We usually try to do this immediately.</li><li>Developer and reviewer sit together. If there are some changes that would affect/help another developer, we also try to involve them for this process. <br><strong><em>For example:</em></strong><em> Our QA writes acceptance tests. Therefore if there is anything related to her work, we involve her as well.</em></li><li>Developer presents the pull request:<br>- Which part is really important that reviewer should double or triple check?<br>- Is there any new thing? <br>- Any new approach? <br>- Any new library? <br>- What did you learn? Any tips that we should know?<br>- Did you make any mistake and if yes share it with us, thus we won’t make the same mistake.</li><li>Reviewer checks the pull request and double/triple checks the critical parts along with the developer and give feedback if necessary.</li><li>Reviewer asks questions to clarify ambiguous parts.</li><li>If there is any part should be changed, reviewer and developer do pair programming. Reviewer fixes the part together with the developer. It’s amazing how much you learn by doing pair programming.</li></ul><p>It sounds as if this approach takes a lot of time but on the contrary it shortened our code review duration drastically.</p><p>As a result:</p><ul><li>Everyone who is involved in this process learn something.</li><li>Developer can explain the code changes with why/how. Thus the changes makes more sense to reviewer. Since we do code review as soon as possible, everything is fresh in developer’s mind, therefore developer can easily explain all changes in detail. In most cases, developer shows some link to reviewers like why he/she did etc. Good opportunity to learn new things for the reviewers.</li><li>This process creates a discussion opportunity. Usually we get a lot of ideas during this process. We write them down in our internal whiteboard which is next to us in order to execute them later.</li></ul><h3>In order to make this approach successful:</h3><h3>1. Pull request has to be meaningful.</h3><h4>Atomic commits</h4><p>Imagine a pull request with one commit and 5k changes. This is terrible and super demotivating. No one would want to review this kind of code, because it’s boring. The pull request might contain renaming, removing or something super important. You don’t know where to focus most of the time. You don’t know where is the important part etc.</p><p>In order to solve this problem, we applied single responsibility principle to the commits.</p><p>Each commit should have one and only one responsibility.</p><ul><li>Did you update any dependency? One commit<br>- Update autovalue to x.y.z</li><li>Did you introduce a new utility class? One commit for introduction part.<br>- Add Dates utility class to simplify all date operations.</li><li>One commit for the integration part.<br>- Replace the date conversion in Login with Dates</li><li>One commit for the removing redundant helper methods etc.<br>- Remove redundant date implementations</li></ul><p>There is nothing that prevent from doing to make many commits. It doesn’t matter whether it’s one letter or one line as long as the commit contains only relevant changes.</p><h4>Commit message</h4><p>It’s so common that most developers don’t care about commit messages. Frankly, they are right most of the time, because these messages are not used anywhere. If you don’t use something, you probably don’t give enough attention.</p><p>But we use the commit messages in a few places, therefore we need to make them meaningful.</p><ul><li><strong>Change log for QA builds<br></strong>Each build contains a change log which is automatically generated by the commit messages. Therefore they have to be meaningful.</li><li><strong>Summary for the reviewer<br></strong>Reviewer should understand the purpose of the pull request by just reading commit messages in the first screen. It will prepare him/her to load some context into his/her mind.</li></ul><p>There are many articles about the commit message convention. We basically consider the commit message upfront, like to “solve this problem” and “take this action”</p><p>For example:</p><ul><li>Move the login button to the left.</li><li>Add Dates utility class in order to provide a unified date operations.</li><li>Update Gson to X.Y.Z</li><li>Remove redundant foo module.</li></ul><p>But in my opinion it doesn’t have to be like this. As long as it has meaningful content, it doesn’t matter how it is written. Team should decide what is the best way.</p><h3>2. There should be good enough automation</h3><p>Imagine the code review process when there is no quality check or any other automation. You don’t even know whether the code actually works. This is a huge waste of time. Reviewer has to check everything, line length, spaces, method lengths, implementation and reviewer might event need to pull the code and run. Because you don’t even know these changes also affects something else. Super boring, a huge amount of time is wasted. We need to channel focus to important part.</p><p>In order to avoid this, we basically try to automate everything and we try to increase the level of automation each day. We run the following operations in our CI server:</p><ul><li>Static code analyzers (Lint, checkstyle)</li><li>Automated tests (Unit, functional and integration tests)</li><li>Pull request report which contains the information of the new changes.<br>- Apk size, old size, new size, difference<br>- Method count, old, new etc.<br>- Test results, any tests which takes longer than expected etc.<br>- Lint, checkstyle warnings<br>- Any changes on permissions(new, removed)<br>- Any change on the build tools etc etc. <br>This gives a lot of information to reviewer upfront.</li></ul><h4>There are times that we couldn’t automate some small things.</h4><p><strong>For example:</strong> We usually put the single annotations next to the method/variable name.</p><pre>@Override public void something()</pre><p>At first we couldn’t put this check to checkstyle, therefore CI didn’t catch this issue if you had something like below.</p><pre>@Override<br>public void something()</pre><p>For us, if we can’t automate it, it’s something insignificant and if we can live with it for a while, then we don’t bother with it during the code review at all. We can channel our focus to important parts.</p><p>By having all of these automation gives the reviewer more time to focus on important parts and requires less time to finish code review process.</p><blockquote>As rule of thumb, working should be fun and educational, therefore we try to make every single process fun and team-work.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcaa3b1d12b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[No-op versions for dev tools]]></title>
            <link>https://medium.com/@orhanobut/no-op-versions-for-dev-tools-b0a865934398?source=rss-fbe7407255e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0a865934398</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Orhan Obut]]></dc:creator>
            <pubDate>Fri, 19 Aug 2016 18:53:37 GMT</pubDate>
            <atom:updated>2016-09-25T13:04:46.909Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>“In computer science, a NOP or NOOP (short for No Operation) is an assembly language instruction, programming language statement, or computer protocol command that does nothing.”</blockquote><blockquote>wiki</blockquote><p>For each pull request we summarize build info along with the possible changes and send an email to corresponding group in CI server.</p><p>Recently we submitted a pull request and there were some interesting metrics. Pull request increased the apk size and method count. The following data is a small part of the report. <a href="https://github.com/orhanobut/buildreport">Check buildreport for more details</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CS5r5Ixoaw0wHq-CIFVtVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PWdsrexTJrtxTm84F5SQaQ.png" /></figure><p>The only major change in the commits was introducing Facebook Stetho. It’s a great debugging tool and we need for some specific reasons but we definitely don’t want to increase the method count and size in the release apk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qrh1oSyct9LIvsLIl9eT9A.png" /></figure><p>We have a few options to get rid of them from our release apk.</p><h3>Proguard</h3><p>We don’t use it (yet). I guess it’s time to consider it again.</p><h3>Use no-op version from the library</h3><p>Some libraries provide no-op version out of box such as <a href="https://github.com/square/leakcanary">LeakCanary</a>. Some don’t (be like LeakCanary).</p><p>releaseCompile compiles no-op implementation which your apk won’t contain any redundant code from the library.</p><pre>dependencies {<br>   debugCompile &#39;...:leakcanary-android&#39;:1.4-beta2&#39;&#39;<br>   releaseCompile &#39;...:leakcanary-android-no-op:1.4-beta2&#39;<br> }</pre><h3>Libraries that don’t provide no-op version</h3><p>For example: Stetho doesn’t have this option out of box, therefore we have to create it by ourselves. Stetho has a lot of optional configurations, thus they don’t want to have a no-op version.</p><p>We have a few options to create our own no-op version. Essentially all does the same thing, the only difference is the implementation.</p><h4>Create a module for the library</h4><p>Create no-op version of the library as module. In this case we only used one method of Stetho, so let’s create a no-op for this method in the module.</p><ul><li>Create a module. File -&gt; New -&gt; New Module</li><li>Create the used class exactly same name as the tool under the same package.</li><li>Add no-op implementation.</li><li>In build.gradle specify debugCompile for the tool dependency and releaseCompile for no-op version.</li><li>For non-debug builds, there will be only no-op implementation, nothing else.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*laMyqTX_Ljy81XpKRhY7Kg.png" /></figure><h4>Use variant source sets</h4><p>Another solution is that you can directly manage variants in the source set level.</p><ul><li>Create release source set folder. src/release</li><li>Create a class exactly same name as the tool under the same package.</li><li>Add no-op implementation.</li><li>In build.gradle specify only for debugCompile</li><li>For non-debug builds, there will be only no-op implementation, nothing else.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VPmXTOsV8N8KyqLoL3zVgg.png" /></figure><h4>Use DebugApplication</h4><p>Since most of the debugging tools are initialized in application class, we can take advantage of that.</p><ul><li>Create debug source set folder. src/debug</li><li>Create DebugApplication class which inherits from your custom Application.</li><li>Initialize the dev tools inside DebugApplication.</li><li>Create AndroidManifest.xml under debug source set. We take advantage of the manifest merger and replace the actual application with DebugApplication by using “tools:replace”. This will replace “android:name” tag value with “.DebugApplication”</li><li>In build.gradle specify only for debugCompile</li><li>For non-debug builds, there will be only no-op implementation, nothing else.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rGxqVqiCmqT0h38hEmiCfA.png" /></figure><h4>Use variant source sets with DevUtils</h4><p>Since we use a couple of different developer tools, we prefer to have them in variant source sets, but instead of creating a class for each tool, we created a utility class which keeps all the logic inside, therefore we don’t have to think which class is under which package etc etc.</p><ul><li>Create source sets for each build type. src/debug, src/release</li><li>Create a utility class such as DevUtils</li><li>Create appropriate helper methods for each developer tools. ie: initStetho, initSomethingElse</li><li>Use DevUtils in your application. DevUtils.initStetho(this) etc</li><li>In build.gradle, use the appropriate compile option, usually it will be debugCompile unless you have other build types which you have specific tools for them.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6CpJk9E-0nzejVu7aei3vg.png" /></figure><blockquote>Each solution has pros and cons but overall it’s great to use no-op versions for your build apk. Better for everyone.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0a865934398" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happened last week: 04]]></title>
            <link>https://medium.com/@orhanobut/what-happened-last-week-04-13cb8f0f2502?source=rss-fbe7407255e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/13cb8f0f2502</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Orhan Obut]]></dc:creator>
            <pubDate>Fri, 12 Aug 2016 17:47:25 GMT</pubDate>
            <atom:updated>2016-08-12T17:47:25.254Z</atom:updated>
            <content:encoded><![CDATA[<h3>Android Studio</h3><p>Make your logcat more beautiful by changing settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*wh2lPaBQmw6JXBvlJhM0Qw.png" /></figure><p>Perfect explanation for git fast forward. <a href="https://sandofsky.com/images/fast_forward.pdf">Original link</a></p><iframe src="https://drive.google.com/viewerng/viewer?url=https%3A//sandofsky.com/images/fast_forward.pdf&amp;embedded=true" width="600" height="780" frameborder="0" scrolling="no"><a href="https://medium.com/media/6adb23449e7a87e18821d4a190d13d27/href">https://medium.com/media/6adb23449e7a87e18821d4a190d13d27/href</a></iframe><h3>Others</h3><p>A tip to reveal masked passwords in the browsers.</p><p><a href="http://www.hongkiat.com/blog/reveal-hidden-passwords-in-browsers/">How To Reveal Hidden Passwords (Asterisks) In Web Browsers</a></p><h3>Android Tools</h3><p>You can get the required permission for the apk with aapt. You can find “aapt” under androidsdk/build-tools/&lt;versions&gt;/aap. I had an issue to execute the command, therefore I copied “aapt” to platform-tools and it worked!</p><pre>$ aapt d permissions path/to/your.apk</pre><p>Get apk method count</p><pre>$ cat classes.dex | head -c 92 | tail -c 4 | hexdump -e &#39;1/4 &quot;%d\n&quot;&#39;</pre><p>Get minSdkVersion and targetSdkVersion from apk. Version number will be displayed in a text as hex, therefore you need to manipulate the text and convert it to decimal</p><pre>$ aapt list -a app-release.apk | grep &quot;minSdkVersion&quot;</pre><pre>//output  A: android:minSdkVersion(0x0101020c)=(type 0x10)0x10</pre><h3>Python</h3><ul><li>Manipulating html content with python is super easy. You can use <a href="https://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a></li><li>You can use <a href="https://www.pylint.org/">pylint</a> for static analyzing the code. Super awesome.</li></ul><pre>$ pip install pylint<br>$ pylint your_python_file.py</pre><h3>Gradle</h3><ul><li>Use “continue” in order to continue tasks after a failure task.</li></ul><pre>$ ./gradlew failTask nextTask --continue</pre><h3>Tests</h3><p>Use <a href="https://github.com/junit-team/junit4/wiki/ignoring-tests">ignore annotation</a> to ignore unit tests instead of ugly comment out</p><pre>@ Ignore(&quot;I can&#39;t solve this test&quot;)<br>@ Test public void mytest(){}<br></pre><p>Great talk about how to make acceptance/functional tests easier and more readable. Testing Robots(Page object concept)</p><p><a href="https://realm.io/news/kau-jake-wharton-testing-robots/">Instrumentation Testing Robots</a></p><h3>Git</h3><p>How to get the current branch name.</p><pre>$ git rev-parse --short HEAD</pre><p>Use aliases for git</p><pre>$ git config --global alias.lol &quot;log --oneline --graph --decorate&quot;<br>$ git config --global alias.lo &quot;log --oneline --decorate&quot;<br>$ git config --global alias.l &quot;log --oneline&quot;<br>$ git config --global alias.st &quot;status&quot;</pre><pre>$ git lol<br>$ git lo<br>$ git l<br>$ git st</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13cb8f0f2502" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happened last week: 03]]></title>
            <link>https://medium.com/@orhanobut/log-03-284b0c445190?source=rss-fbe7407255e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/284b0c445190</guid>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Orhan Obut]]></dc:creator>
            <pubDate>Fri, 29 Jul 2016 07:25:41 GMT</pubDate>
            <atom:updated>2016-07-29T08:08:09.426Z</atom:updated>
            <content:encoded><![CDATA[<p>A regular android developer log</p><h3>Firebase</h3><ul><li>You can’t use the same application id (package name) and sha1 in different projects for Firebase. The main reason is oAuth. <a href="https://goo.gl/EMHrkF">More details here</a>. Just a quick summary of the details, you only need sha1 for Invites/Dynamic Links and Authentication features.</li><li>You can delete any application in your Firebase project now.</li><li>You have a limit to create projects in Firebase for free tier and deleting a project also takes time, 7 days. Therefore be careful.</li><li>You can use <a href="https://firebase.google.com/docs/remote-config/">Firebase RemoteConfig</a> in order to provide force update for your application. This feature is super useful for global dynamic key-value pairs.</li></ul><h3>Logging</h3><ul><li><a href="https://medium.com/fuzz/getting-the-most-out-of-crashlytics-380afb703876#.qtl2b949y">A nice article about leveraging crashlytics logs</a>. We use <a href="https://github.com/jakewharton/timber">Timber</a> for each log and <a href="https://github.com/orhanobut/logger">Logger</a> for better display. Rest of the operations are implementation detail and added inside Timber implementation. I strongly suggest you to abstract away all your logs with Timber or any other abstraction.</li></ul><pre>Timber.<em>plant</em>(new Timber.DebugTree() {<br>  @Override protected void log(...) {<br>    Logger.<em>log</em>(priority, tag, message, t);<br>  }<br>});</pre><ul><li>We added git hash and build time for Crashlytics logs. You can find the details in the link above. Instead of putting them into different build types, you can just put the build config fields inside defaultConfig block , it won’t harm to have the actual data for other build types.</li></ul><pre>Fabric.<em>with</em>(this, new Crashlytics());<br>Crashlytics.<em>setString</em>(&quot;GIT_SHA&quot;, BuildConfig.<em>GIT_SHA</em>);<br>Crashlytics.<em>setString</em>(&quot;BUILD_TIME&quot;, BuildConfig.<em>BUILD_TIME</em>);</pre><h3>Others</h3><ul><li><a href="https://medium.com/@dmytrodanylyk/android-strings-xml-things-to-remember-c155025bb8bb#.yt8rizhs3">Here is a good article about strings.xml</a>. Localization seems easy to everyone, since you only change a text or add another strings.xml file with another language. But to be honest, the time you spend for this manual work is quite a lot. There are a lot of back and forth decisions. We have the same issue and we tried a couple of things and and decide to automate this process. More info will be coming soon…</li><li>Use ContextCompact.getColor() instead of Context.getColor() for compatibility reasons. Usually it’s highlighted but somehow it is not highlighted in FirebaseMessagingService etc. Probably due to missing source.</li><li>Had a discussion about how play store actually nominates featured apps. There were a couple of ideas since there is no certain checklist for this or at least I couldn’t find. Material design, supporting latest api, tablet support and maybe accessibility. But most importantly someone actually has to contact a person from Google…</li><li>We moved from Travis to in-house Jenkins solution. Company was already using Jenkins and we find it more easy to configure and use. It’s also good for running UI Tests, nightly builds and of course it is now way faster since some dependencies are already downloaded. I also like that there are many plugins for your needs.</li><li>If you want to send a push notification from GCM/FCM in terminal, use the following command. Believe me sooner or later you will need this.</li></ul><pre>curl <br>-s &quot;https://android.googleapis.com/gcm/send&quot; <br>-H &quot;Authorization: key=[SERVER_API_KEY]&quot; <br>-H &quot;Content-Type: application/json&quot; <br>-d &#39;{&quot;to&quot;: &quot;[REG_TOKEN_HERE]&quot;, &quot;data&quot;: {&quot;key&quot;: &quot;value&quot;}}&#39;</pre><ul><li>We use Fabric Beta for QA. Any merge to master creates staging and release versions and upload both of them to Fabric Beta. But there was always “play store upload” friction. And finally we added play store API to our CI. Any merge to master also uploads a release version to alpha channel in play store now. Annoying friction is removed. <a href="https://guides.codepath.com/android/Automating-Publishing-to-the-Play-Store">Here is a good guide for play store api integration</a>. Note: We use the jenkins integration.</li></ul><h3>Git</h3><p>First of all, <a href="https://www.atlassian.com/git/tutorials/">Atlassian git tutorial</a> is the best tutorial so far in my opinion. Super clear and easy to understand.</p><ul><li>Since git 1.8.4, you can use “@” instead of “HEAD”. If you don’t know what is head, <a href="http://stackoverflow.com/questions/2304087/what-is-head-in-git">here is a good discussion</a>.</li><li>rev-parse can be used for manipulation</li></ul><pre>// Last HEAD commit sha1<br>$ git rev-parse HEAD</pre><pre>// Previous HEAD commit sha1<br>$ git rev-parse HEAD~</pre><pre>// Total commit count<br>$ git rev-list --count HEAD</pre><pre>// One line representation for the history<br>$ git log --oneline</pre><pre>// One line with branch or tag info<br>$ git log --oneline --decorator</pre><pre>// Last 2 commits<br>$ git log -2</pre><pre>// Show all commits by range<br>$ git log &lt;since&gt;..&lt;until&gt;</pre><pre>// Prevent to display merge commits<br>$ git log --no-merges</pre><ul><li>We use git commit count number for android version number. If you are using github and if you always use rebase strategy instead of merge, you can use the merge count, that will be more convenient.</li></ul><pre>$ git rev-list --count --merges HEAD</pre><ul><li>Get all commit messages between the last and previous merge excluding merge commit messages. This is useful to get all commits for the last github pull request merge. We use this for Fabric Beta release notes.</li></ul><pre>$ git log @~.. --oneline --no-merges --pretty=%B</pre><ul><li>$ git reflog is purely local. <a href="http://stackoverflow.com/questions/17857723/whats-the-difference-between-git-reflog-and-log">Here is a good discussion about the difference between git log and reflog</a></li></ul><h3>Gradle build has 3 phases:</h3><ul><li><strong>Initialization phase:</strong> Gradle determines which projects are going to be involved. Usually determined by the settings.gradle file.</li><li><strong>Configuration phase:</strong> Project objects are created along with build scripts executions. This is evaluation part. For example: “afterEvaluation” happens exactly at the end of this configuration phase and before the execution phase.</li><li><strong>Execution phase:</strong> Gradle determines which sub tasks are going to be executed and start executing the tasks.</li></ul><p><a href="https://docs.gradle.org/current/userguide/build_lifecycle.html#sec:build_phases">For more info about gradle build phases and lifecycle</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=284b0c445190" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happened last week: 02]]></title>
            <link>https://medium.com/@orhanobut/log-02-528d912fd61f?source=rss-fbe7407255e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/528d912fd61f</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Orhan Obut]]></dc:creator>
            <pubDate>Tue, 19 Jul 2016 18:55:58 GMT</pubDate>
            <atom:updated>2016-07-29T08:09:02.286Z</atom:updated>
            <content:encoded><![CDATA[<p>A regular android developer log</p><ul><li><a href="https://firebase.google.com/docs/cloud-messaging/">FCM</a> implementation is far easier than old <a href="https://developers.google.com/cloud-messaging/android/start">GCM</a> implementation. Many frictions are gone. Firebase dashboard also provides Notifications feature which I used it in order to test the integration. There is a different concept now (I’m not sure if they had it before). Notification Message and Data Message. Read the whole <a href="https://firebase.google.com/docs/cloud-messaging/concept-options">documentation</a> before the implementation. It’s important to understand it.</li><li>Removed interfaces for Presenters and Repositories. Inspired from this article: http://goo.gl/NU1qDD</li><li>Decided to merge data module into presentation module. Our new structure will be completely grouped by feature. There are cons/pros. I’ll share the results after a while. The whole idea is to reduce the development frictions. We are doing a lot of experiments to find out the best for our setup.</li><li>Started to use AutoValue.</li><li>Did my first test for Services. ServiceTestRule. Thumb of rule for instrumentation tests, do not inherit BlaBlaTestCase classes, instead use the corresponding TestRule.</li><li>If you don’t care about the result, RxJava provides subscribe() method without any arguments.</li><li>Accidentally realized that you can actually move any window to anywhere in Android Studio. Very useful to move terminal into main tabs when doing profiling and yes I do use internal AS terminal quite often.</li><li>Started to create a wrapper type for the list responses. In almost every case I had to create this wrapper class anyway. Very useful to control the whole information and expand the needs without altering many places.</li></ul><p><strong>For example:</strong> Fetching list of prices from the server and use the data as list in every where. Instead create a Prices type and keep the list inside and use Prices object everywhere.</p><pre>List&lt;Price&gt; getPrices();      // Not ideal. <br>Prices getPrices();           // GOOD</pre><pre>class Prices {<br>  List&lt;Price&gt; priceList;<br>}</pre><ul><li>You can rename a file in Github directly if you made a mistake. This happened to me a few times and each time I tried to use git, I kind of lost after a few seconds and each time I was in rush.</li><li>Nice article about <a href="https://developer.android.com/training/articles/user-data-ids.html">best practices for unique identifiers in Android</a>. The best part is use cases, pros and cons of the each solution.</li><li>Google improved/updated some documentation about android, even the look&amp;feel is different now. I’m satisfied with the information they provide. Quite nice. I guess these things had to happen because of Firebase? Looking forward to see these changes in everywhere.</li><li>A great article about <a href="https://goo.gl/ezIjKu">Instagram android application evolution</a>. Although not every case is applicable to most of the teams, since no one has huge team as they do. Therefore 3rd party libraries are quite helpful. Use it when you can’t do it yourself and spend more time on your business problems.</li></ul><p><a href="https://medium.com/@orhanobut/log-01-88d476fa638d">Log 01</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=528d912fd61f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happened last week: 01]]></title>
            <link>https://medium.com/@orhanobut/log-01-88d476fa638d?source=rss-fbe7407255e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/88d476fa638d</guid>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Orhan Obut]]></dc:creator>
            <pubDate>Thu, 14 Jul 2016 20:08:56 GMT</pubDate>
            <atom:updated>2016-07-29T08:09:31.353Z</atom:updated>
            <content:encoded><![CDATA[<p>A regular android developer log</p><ul><li>I recently started to use <a href="https://github.com/google/truth">Truth</a> over <a href="http://joel-costigliola.github.io/assertj/assertj-core-quick-start.html">AssertJ</a>. One of the reason is that I cannot use AssertJ version 2.0 and above in android projects due to <a href="https://goo.gl/qIWhVh">transitive dependencies issue</a>.</li><li><a href="https://t.co/an3lbTPAUn">Difference between Compiler vs Transpiling</a></li><li>We started to use “dependencies” in root build.gradle approach. I liked it. I also updated some of my libraries with this approach. The idea came from <a href="https://goo.gl/1jY6bt">Butterknife</a>. One of the advantages is to use them among all modules.</li></ul><pre># build.gradle<br>ext.deps = [                                                   <br>  junit  : &#39;junit:junit:4.12&#39;,                        <br>  truth  : &#39;com.google.truth:truth:0.28&#39;,                          <br>]</pre><pre># app/build.gradle<br>dependencies {<br>  testCompile deps.junit<br>  testCompile deps.truth<br>}</pre><ul><li>We removed the restriction of one line rule for if-else conditions. I feel more comfortable with one line for some situations. The more compact the better. The eyes get used to it fairly fast.</li></ul><pre>if (something) return true;    // OK</pre><pre>if (something)                 // Still bad, should use curly braces<br>    return true; </pre><ul><li>Android emulator doesn’t support Play Services 9.2.0 yet. Therefore we had to stick with 9.0.2 version. Here is the submitted issue <a href="https://goo.gl/mOQit5">https://goo.gl/mOQit5</a></li><li>Article about our documentation first development which we apply in our team. <a href="https://t.co/puh1vhKNHN">https://t.co/puh1vhKNHN</a></li><li>There is an easy way to get keystore information, especially for debug.keystore. Usually you need sha1 info for many reasons.</li></ul><pre>$ ./gradlew signingReport</pre><h3>Notes in general</h3><ul><li>In the early days of unit testing, I used to test package-private methods as well. We completely stopped this approach and abandoned it. We only test the behavior of public API. Other methods are implementation details and should be tested through public API.</li><li>For the new project we are using MVP and we are quite happy about it. We have adjusted it quite a lot. I’ll mention about these changes on the next logs.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88d476fa638d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Test before integration]]></title>
            <link>https://medium.com/@orhanobut/test-before-integrate-e713090070d6?source=rss-fbe7407255e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e713090070d6</guid>
            <category><![CDATA[integration-testing]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Orhan Obut]]></dc:creator>
            <pubDate>Sun, 13 Dec 2015 16:44:35 GMT</pubDate>
            <atom:updated>2016-08-16T17:03:29.245Z</atom:updated>
            <content:encoded><![CDATA[<p>There are many 3rd party libraries out there and we developers are really happy about them. They give us opportunity to focus on our business code. Everything sounds perfect in theory, but in practice we may have some problems.</p><p>Because we don’t know:</p><ul><li>How exactly the library works?</li><li>Does it meet all our requirements?</li><li>Maybe documentation is poor or complicated and we may need to check it out by trying?</li></ul><p>And there is even more…</p><p>Let’s say we decided to give it a try and use the library in our production and have some first hand experience. There are several ways to do that and one of them is:</p><ul><li>Create a branch</li><li>Add the dependencies, implement it in our production code and start debugging/manual testing.</li><li>If everything is OK, merge it to the master branch.</li><li>If something is wrong or if it doesn’t meet our requirements, just delete the branch.</li></ul><p>This approach has a few issues:</p><ul><li>First of all, we want to test the library, but we mix it with our production code. The result may have some problems and we don’t know whether the problem is the library or our production code.</li><li>We need to run the application and we may need to do a lot of steps to go to this particular code and test it. For example:</li></ul><pre><em>Splash screen -&gt; login -&gt; few more clicks -&gt; our test code</em></pre><ul><li>Even if everything works fine, a new version of the library might be uploaded and we want to use it. New changes might have conflicts with the previous one and we may need to spend a lot of time to find out the problem.</li></ul><p>Then how do we make sure the library is stable with all versions and meets our requirements?</p><blockquote>Test it before integration</blockquote><blockquote>A real example: We want to use google places autocomplete API.</blockquote><p><a href="https://developers.google.com/places/android-api/start">Getting Started</a></p><p>According to the documentation there are a couple of steps to get started.</p><ol><li>Add dependencies</li><li>Add API key</li><li>Connect to the Places API</li></ol><p>We add the dependencies and started writing our test case. We want to make sure that our setup is correct and it connects to the Google API successfully.</p><p>Our first test will be to assert the connection status.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fd4d015af20ef6500a701bf874f2867/href">https://medium.com/media/7fd4d015af20ef6500a701bf874f2867/href</a></iframe><p>We run the tests.</p><p><strong>The tests failed.</strong></p><p>We have the following error which tells us to add the API Key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KAVtWkXn7C32pyt-8hXFsA.png" /></figure><p>We add the missing API key and run it again.</p><p><strong>The tests failed again.</strong></p><p>GoogleApiClient connects to the server asynchronously. Thus we change the test structure a little bit and wait for the response before running the tests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/264716b072a4f8b592dee121bc01f68c/href">https://medium.com/media/264716b072a4f8b592dee121bc01f68c/href</a></iframe><p><strong>Tests passed!</strong></p><p>We basically asserted our setup works.</p><p>Now time to test the autocomplete API. Basically, we add another test to assert that calling this API will return successful response.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6924fc2b9b5546ed2acd44a2191c28e0/href">https://medium.com/media/6924fc2b9b5546ed2acd44a2191c28e0/href</a></iframe><p>We run it again</p><p>Great!<strong> All tests passed</strong>.</p><p>Now we can dive deep and do more tests to check if the API is feasible for our needs</p><h3>Conclusions</h3><ul><li>We assert that the 3rd party library meets our requirements</li><li>We assert that the library works</li><li>We have a test case that covers future version changes of the library</li><li>We have a test case which will save us a lot of time when there is a bug</li></ul><blockquote>Write tests to save yourself from a lot of troubles.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e713090070d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>