<?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 Roi Bareket on Medium]]></title>
        <description><![CDATA[Stories by Roi Bareket on Medium]]></description>
        <link>https://medium.com/@roibareket-1961?source=rss-f7123bf2fc3b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*fWqWj5OrKd57SOa4n4GTxw.jpeg</url>
            <title>Stories by Roi Bareket on Medium</title>
            <link>https://medium.com/@roibareket-1961?source=rss-f7123bf2fc3b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 07:09:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@roibareket-1961/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[Saving your tokens — the right way]]></title>
            <link>https://roibareket-1961.medium.com/saving-your-tokens-the-right-way-d418adf26695?source=rss-f7123bf2fc3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d418adf26695</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[token]]></category>
            <category><![CDATA[credentials]]></category>
            <category><![CDATA[account-manager]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Roi Bareket]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 08:27:08 GMT</pubDate>
            <atom:updated>2021-01-11T08:31:26.079Z</atom:updated>
            <content:encoded><![CDATA[<h3>Saving your tokens — the right way</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j6T9Bs2RMIlrXvOXvyczCw.png" /></figure><p>Many Android apps has users. They login, the own credentials <br>and unfortunately, their credentials are compromised.<br>The right way to store credentials in Android is using AccountManager.</p><p><strong>Benefits:</strong><br>* let the OS handle securing your credentials<br>* support multiple accounts if needed<br>* allow to share credentials cross apps from the same publisher (keystore)<br>* hold credentials after clear data<br>* Credentials are kept securely, even on rooted devices (unlike sharedPrefs, hidden files or database)</p><p><strong>How it works:<br></strong>AccountManager give you access to account data (key-value)<br>Accounts has type (company identifier) and could be fetched by type<br>Your access token should be saved using the AccoutManager</p><p><strong>Step 1: </strong>declare your account in res/xml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce485784436bcab6d08d7356fd4d1145/href">https://medium.com/media/ce485784436bcab6d08d7356fd4d1145/href</a></iframe><p><strong>Step 2:</strong> Declare account permissions, authentication service and login activity</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/845db13a5187266f2cfa2bd79546390f/href">https://medium.com/media/845db13a5187266f2cfa2bd79546390f/href</a></iframe><p><strong>Step 3:</strong> Declare your authenticator service. can be reached from <br>phone settings&gt;accounts.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98ebbcc2e4de0f01746e6dc051c37f3a/href">https://medium.com/media/98ebbcc2e4de0f01746e6dc051c37f3a/href</a></iframe><p><strong>Step 4:</strong> Declare your CompanyAuthenticator<br>addAccount() will allow adding account from phoneSettings&gt;account&gt;new<br>getAuthToken() for getting our token.<br>* there are more options there. look at my github for more</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5830cc42bbb47b200b59a4f490f662f/href">https://medium.com/media/c5830cc42bbb47b200b59a4f490f662f/href</a></iframe><p><strong>Step 5:</strong> Add account to account manager after login<br>* I create account always with a token. it’s not mandatory, but simplify everything a lot</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb295324675dde5372f01a99b7292b7e/href">https://medium.com/media/cb295324675dde5372f01a99b7292b7e/href</a></iframe><p>Summary: <br>Protect your users by using AccountManager to save your access tokens. <br>To speed up, you can load your credentials to the RAM by reading them only once from the account manager.<br>Take a look at my <a href="https://github.com/roibareket/NetworkingOverview">github project</a> for more details<br>Good lock ❤</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d418adf26695" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Animate image rotation like a PRO]]></title>
            <link>https://roibareket-1961.medium.com/animate-image-rotation-like-a-pro-c08d2bd986c6?source=rss-f7123bf2fc3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c08d2bd986c6</guid>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[image]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[rotation]]></category>
            <dc:creator><![CDATA[Roi Bareket]]></dc:creator>
            <pubDate>Sat, 02 Nov 2019 11:29:46 GMT</pubDate>
            <atom:updated>2019-11-10T16:20:17.019Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-h1twBQoyT_uKsU3azrWLA.jpeg" /></figure><p>So you wrote your very cool Android app, and inside you want to capture an image from Camera / Gallery.</p><p><strong>The issue:</strong> You may need to rotate it in your app. So you set an imageView and a rotation button:</p><pre>&lt;<strong>LinearLayout ...<br>        android:orientation=&quot;vertical&quot;</strong>&gt;<br><br>    &lt;<strong>ImageView ... </strong>/&gt;<br><br>    &lt;<strong>Button ...<br>            android:onClick=&quot;onRotateClick&quot;</strong>/&gt;<br>&lt;/<strong>LinearLayout</strong>&gt;</pre><p><strong>The naive approach:</strong> Just reload your image but add rotation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*Qn8Sk4MPMzPugLLbyfyp9Q.gif" /></figure><pre>fun onRotateIconClick(view: View){<br>   GlideApp<br>       .with(context)<br>       .load(&lt;imageUrl&gt;)<br>       .transform(Rotate(90))<br>       .into(imageView)<br>}</pre><p>Yes, it does the trick. Yes, the product may say good job. But it doesn’t look great.</p><p><strong>So you add animation:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*berDirWuzteQkDHopTfAoA.gif" /></figure><pre><strong>fun </strong>onRotateClick(view: View){<br>    findViewById&lt;ImageView&gt;(R.id.<em>image</em>).animate().<em>apply </em><strong>{<br>        </strong>rotationBy(90f)<br>        <em>duration </em>= 300<br>    <strong>}</strong>.start()<br>}</pre><p>You go to you’re product, you both are happy , Than QA and this happens:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*V19kz5AJtSkWbRQiusp_BQ.gif" /><figcaption>the image drawn outside it’s boundaries (top &amp; bottom)</figcaption></figure><p>View rotation doesn’t really work good with rectangles :(</p><p><strong>the solution: </strong>Animate with Image matrix &amp; image height change</p><ol><li>Prepare your ImageView for matrix manipulation</li></ol><pre>&lt;ImageView ...<br>    <strong>android:scaleType=&quot;matrix&quot;/&gt;</strong></pre><p>2. Load your initial image in the right scale</p><pre><strong>fileImg</strong>.setImageBitmap(bitmap)<br><br><strong>if </strong>(bitmap.<em>width </em>&gt; 0) {<br>    <strong>fileImg</strong>.<em>apply </em><strong>{<br>        val </strong>scale = (<strong>fileImg.measuredWidth</strong>) / <em>drawable</em>.<em>intrinsicWidth</em>)<br>        <em>layoutParams</em>.<strong>height </strong>= (scale * <em>drawable</em>.<em>intrinsicHeight</em>).toInt()<br>        <em>imageMatrix </em>= <em>scaleMatrix</em>(scale, scale)<br>    <strong>}<br></strong>}</pre><p>3. Rotate the image smoothly</p><pre>val imageRotation = 0</pre><pre><strong>private fun </strong>animateImageHeight(view: View) {<br>    <em>with</em>(<strong>binding</strong>.<strong>fileImg</strong>) <strong>{<br>        val </strong>drawableWidth = <em>drawable</em>.<em>intrinsicWidth</em>.toFloat()<br>        <strong>val </strong>drawableHeight = <em>drawable</em>.<em>intrinsicHeight</em>.toFloat()<br>        <strong>val </strong>viewWidth = <em>measuredWidth</em>.toFloat()<br>        <strong>val </strong>viewHeight = <em>measuredHeight<br>        </em><strong>val </strong>rotation = <strong>imageRotation </strong>% 360<br>        <strong>val </strong>newRotation = (rotation + 90)<br><br>        <strong>val </strong>newViewHeight: Int<br>        <strong>val </strong>imageScale: Float<br>        <strong>val </strong>newImageScale: Float<br>        <strong>when </strong>(rotation) {<br>            0, 180 -&gt; {<br>                imageScale = viewWidth / drawableWidth<br>                newImageScale = viewWidth / drawableHeight<br>                newViewHeight = (drawableWidth * newImageScale).toInt()<br>            }<br>            90, 270 -&gt; {<br>                imageScale = viewWidth / drawableHeight<br>                newImageScale = viewWidth / drawableWidth<br>                newViewHeight = (drawableHeight * newImageScale).toInt()<br>            }<br>            <strong>else </strong>-&gt; <strong>throw </strong>UnsupportedOperationException(<strong>&quot;rotation can 0, 90, 180 or 270. ${</strong>rotation<strong>} is unsupported&quot;</strong>)<br>        }<br><br>        ValueAnimator.ofFloat(0f, 1f)<br>            .<em>apply </em><strong>{<br>                </strong><em>interpolator </em>= AccelerateDecelerateInterpolator()<br>                <em>duration </em>= <em>resources</em>.getInteger(android.R.integer.<em>config_mediumAnimTime</em>)<br>                    .toLong()<br>                <em>addListener</em>(<br>                    onStart = <strong>{<br>                        binding</strong>.<strong>rotateImageBtn</strong>.<em>isClickable </em>= <strong>false<br>                    }</strong>,<br>                    onEnd = <strong>{<br>                        imageRotation </strong>= newRotation % 360<br>                        <strong>binding</strong>.<strong>rotateImageBtn</strong>.<em>isClickable </em>= <strong>true<br>                    }</strong>)<br><br>                addUpdateListener <strong>{ </strong>animation <strong>-&gt;<br>                    val </strong>animVal = animation.<em>animatedValue </em><strong>as </strong>Float<br>                    <strong>val </strong>complementaryAnimVal = 1 - animVal<br><br>                    <strong>val </strong>animatedHeight =<br>                        (complementaryAnimVal * viewHeight + animVal * newViewHeight).toInt()<br>                    <strong>val </strong>animatedScale =<br>                        (complementaryAnimVal * imageScale + animVal * newImageScale)<br>                    <strong>val </strong>animatedRotation =<br>                        (complementaryAnimVal * rotation + animVal * newRotation)<br><br>                    <em>layoutParams</em>.<strong>height </strong>= animatedHeight<br>                    <em>imageMatrix </em>= <em>rotationMatrix</em>(<br>                        animatedRotation,<br>                        drawableWidth / 2,<br>                        drawableHeight / 2<br>                    ).<em>apply </em><strong>{<br>                        </strong>postScale(<br>                            animatedScale,<br>                            animatedScale,<br>                            drawableWidth / 2,<br>                            drawableHeight / 2<br>                        )<br>                        postTranslate(-(drawableWidth - <em>measuredWidth</em>) / 2, -(drawableHeight - <em>measuredHeight</em>) / 2)<br>                    <strong>}<br>                    </strong>requestLayout()<br>                <strong>}<br>            }</strong>.start()<br><br>    <strong>}<br><br></strong>}</pre><p>the end up result on real gallery image case would be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*CzTWiNwB-S2Jm2sICpxESA.gif" /></figure><p>Much better now :)</p><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_image"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PYxBP_WV7LI6zc-zdUkNqQ.png" /></a></figure><p>📝 Read this story later in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_read_later_text">Journal</a>.</p><p>👩‍💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. <a href="https://usejournal.com/newsletter/noteworthy-in-tech/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_text">Read the Noteworthy in Tech newsletter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c08d2bd986c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>