<?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 MR kotlin on Medium]]></title>
        <description><![CDATA[Stories by MR kotlin on Medium]]></description>
        <link>https://medium.com/@mrkotlin?source=rss-ae10c9b0a018------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kPiTVRm0zVFXQMNHGwxVbA.png</url>
            <title>Stories by MR kotlin on Medium</title>
            <link>https://medium.com/@mrkotlin?source=rss-ae10c9b0a018------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 15:45:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mrkotlin/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[GESTURE DETECTOR ON VIEWS]]></title>
            <link>https://medium.com/@mrkotlin/gesture-detector-on-views-5a2712ccb4c4?source=rss-ae10c9b0a018------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a2712ccb4c4</guid>
            <category><![CDATA[android-nougat]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[android-oreo]]></category>
            <dc:creator><![CDATA[MR kotlin]]></dc:creator>
            <pubDate>Fri, 15 Dec 2017 12:57:07 GMT</pubDate>
            <atom:updated>2017-12-15T13:04:39.438Z</atom:updated>
            <content:encoded><![CDATA[<p>Gesture detector is implemented to detect gestures like single tap,double tap, single tap confirmed, onfling , scrolling etc,.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*RcMOuzj3mzLlRrHx6VI2Qg.png" /></figure><pre>&lt;Button</pre><pre>android:textColor=&quot;@android:color/white&quot;</pre><pre>android:backgroundTint=&quot;@android:color/holo_blue_dark&quot;</pre><pre>android:text=&quot;touch me &quot;</pre><pre>android:layout_centerInParent=&quot;true&quot;</pre><pre>android:id=&quot;@+id/button&quot;</pre><pre>android:layout_width=&quot;match_parent&quot;</pre><pre>android:layout_height=&quot;110dp&quot; /&gt;</pre><h4>Define gesture detector object</h4><pre>lateinit var mygestureDetector: GestureDetector<br>mygestureDetector = GestureDetector(this@MainActivity, MyGestureDetector())</pre><h4><strong>Define touch listener object</strong></h4><pre><strong>var touchListener = View.OnTouchListener{ v,event-&gt; mygestureDetector.onTouchEvent(event) }</strong></pre><h4><strong>Set touch listener on View</strong></h4><pre>button.setOnTouchListener(touchListener)</pre><h4>Gesture Detector class</h4><pre><strong>class </strong>MyGestureDetector : GestureDetector.SimpleOnGestureListener() {<br>    <strong>var GESTURETAGBUTTON </strong>= <strong>&quot;MAINACTIVITYTOUCHMEBUTTON&quot;<br>    override fun </strong>onSingleTapUp(e: MotionEvent?): Boolean {<br>        Log.d(<strong>GESTURETAGBUTTON</strong>,<strong>&quot;single tap up&quot;</strong>)<br>        <strong>return super</strong>.onSingleTapUp(e)<br>    }<br><br>    <strong>override fun </strong>onDown(e: MotionEvent?): Boolean {<br>        Log.d(<strong>GESTURETAGBUTTON</strong>,<strong>&quot;on down&quot;</strong>)<br><br>        <strong>return super</strong>.onDown(e)<br>    }<br><br>    <strong>override fun </strong>onFling(e1: MotionEvent?, e2: MotionEvent?, velocityX: Float, velocityY: Float): Boolean {<br>        Log.d(<strong>GESTURETAGBUTTON</strong>,<strong>&quot;on fling\t Veloxity x \t\t&quot;</strong>+velocityX+<strong>&quot;\t\tveloxity y\t\t&quot;</strong>+velocityY)<br>        <em>//handle the values here        </em><strong>return super</strong>.onFling(e1, e2, velocityX, velocityY)<br>    }<br><br>    <strong>override fun </strong>onDoubleTap(e: MotionEvent?): Boolean {<br>        Log.d(<strong>GESTURETAGBUTTON</strong>,<strong>&quot;double  tap &quot;</strong>)<br>        <strong>return super</strong>.onDoubleTap(e)<br>    }<br><br>    <strong>override fun </strong>onScroll(e1: MotionEvent?, e2: MotionEvent?, distanceX: Float, distanceY: Float): Boolean {<br>        Log.d(<strong>GESTURETAGBUTTON</strong>,<strong>&quot;on scroll\t   \t\t&quot;</strong>+distanceX+<strong>&quot;\t\tveloxity y\t\t&quot;</strong>+distanceY)<br>        <em>//handle the values here        </em><strong>return super</strong>.onScroll(e1, e2, distanceX, distanceY)<br>    }<br>    <strong>override fun </strong>onContextClick(e: MotionEvent?): Boolean {<br>        <strong>return super</strong>.onContextClick(e)<br>    }<br><br>    <strong>override fun </strong>onSingleTapConfirmed(e: MotionEvent?): Boolean {<br>        Log.d(<strong>GESTURETAGBUTTON</strong>,<strong>&quot;single confirmed&quot;</strong>)<br>        <strong>return super</strong>.onSingleTapConfirmed(e)<br>    }<br><br>    <strong>override fun </strong>onShowPress(e: MotionEvent?) {<br>        <strong>super</strong>.onShowPress(e)<br>        Log.d(<strong>GESTURETAGBUTTON</strong>,<strong>&quot;on show press&quot;</strong>)<br>    }<br><br>    <strong>override fun </strong>onDoubleTapEvent(e: MotionEvent?): Boolean {<br>        Log.d(<strong>GESTURETAGBUTTON</strong>,<strong>&quot;on double tap&quot;</strong>)<br>        <strong>return super</strong>.onDoubleTapEvent(e)<br>    }<br><br>    <strong>override fun </strong>onLongPress(e: MotionEvent?) {<br>        <strong>super</strong>.onLongPress(e)<br>        Log.d(<strong>GESTURETAGBUTTON</strong>,<strong>&quot;on long press&quot;</strong>)<br><br>    }<br>}</pre><p><em>Originally published at </em><a href="https://mrkotlin.blogspot.in/2017/12/gesture-detector-on-views-imageview.html"><em>mrkotlin.blogspot.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a2712ccb4c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Butter Knife With Kotlin (No Need)]]></title>
            <link>https://medium.com/@mrkotlin/butter-knife-with-kotlin-no-need-c23e31b38be?source=rss-ae10c9b0a018------2</link>
            <guid isPermaLink="false">https://medium.com/p/c23e31b38be</guid>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-oreo]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[butterknife]]></category>
            <dc:creator><![CDATA[MR kotlin]]></dc:creator>
            <pubDate>Fri, 15 Dec 2017 12:24:17 GMT</pubDate>
            <atom:updated>2017-12-15T12:25:26.611Z</atom:updated>
            <content:encoded><![CDATA[<h3>Butter Knife</h3><p><strong>Butter knife</strong> is a little and light weight library used to inject android components using annotation processing</p><p>If you android app using Kotlin then there is no need for butter knife or findviewbyid , we can simple use view id as view object as in example below</p><p><strong>Textview layout</strong></p><pre>&lt;<strong>TextView<br>    android:id=&quot;@+id/textview&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;55dp&quot;<br>    android:gravity=&quot;center&quot;<br>    android:text=&quot;Hello World!&quot;<br>    android:textAlignment=&quot;center&quot;<br>    android:textAllCaps=&quot;true&quot;<br>    android:textColor=&quot;@color/colorPrimary&quot;/&gt;</strong></pre><p>In the above textview we set textview as id for the textview view we can change color , settext etc,.</p><pre>//you can use this on any methods in lifecycle no need to instantiate the view <br>textview.setTextColor(Color.<em>RED</em>)<br>textview.<em>text </em>= <strong>&quot;this text setted programatically&quot;</strong></pre><h4><strong>Button with onclicklistener with button as id</strong></h4><p><strong>Button Layout</strong></p><pre>&lt;<strong>Button<br>    android:id=&quot;@+id/button&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;55dp&quot;/&gt;</strong></pre><p>Kotlin code for onclick listener</p><pre>button.setOnClickListener <strong>{<br>    </strong>Toast.makeText(<strong>this</strong>@MainActivity, <strong>&quot;${</strong>button.<em>text</em><strong>} clicked &quot;</strong>, Toast.<em>LENGTH_LONG</em>).show()<br>    button.setBackgroundColor(Color.<em>RED</em>)<br><strong>}</strong></pre><h4><strong>ImageView with set image programatically with imageview as id</strong></h4><p><strong>Layout for ImageView</strong></p><pre>&lt;<strong>ImageView<br>    android:id=&quot;match_parent&quot;<br>    android:layout_width=&quot;291dp&quot;<br>    android:layout_height=&quot;99dp&quot;/&gt;</strong></pre><p>Kotlin code for change background color and to set image drawable</p><pre>imageView.setImageDrawable(ContextCompat.getDrawable(<strong>this</strong>@MainActivity, android.R.drawable.<em>ic_menu_share</em>))<br>imageView.setBackgroundColor(Color.<em>GREEN</em></pre><p>Final Look of Layout</p><pre><em>&lt;?</em><strong>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;</strong><em>?&gt;<br></em>&lt;<strong>android.support.constraint.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    tools:context=&quot;com.mrkotlin.mrkotlincustomtoast.MainActivity&quot;<br>    tools:layout_editor_absoluteY=&quot;81dp&quot;</strong>&gt;<br><br>    &lt;<strong>TextView<br>        android:id=&quot;@+id/textview&quot;<br>        android:layout_width=&quot;279dp&quot;<br>        android:layout_height=&quot;55dp&quot;<br>        android:layout_marginBottom=&quot;8dp&quot;<br>        android:layout_marginEnd=&quot;8dp&quot;<br>        android:layout_marginStart=&quot;8dp&quot;<br>        android:layout_marginTop=&quot;8dp&quot;<br>        android:gravity=&quot;center&quot;<br>        android:text=&quot;Hello World!&quot;<br>        android:textAlignment=&quot;center&quot;<br>        android:textAllCaps=&quot;true&quot;<br>        android:textColor=&quot;@color/colorPrimary&quot;<br>        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>        app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>        app:layout_constraintHorizontal_bias=&quot;0.505&quot;<br>        app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>        app:layout_constraintTop_toTopOf=&quot;parent&quot;<br>        app:layout_constraintVertical_bias=&quot;0.043&quot; </strong>/&gt;<br><br>    &lt;<strong>ImageView<br>        android:contentDescription=&quot;@string/app_name&quot;<br>        android:id=&quot;@+id/imageView&quot;<br>        android:layout_width=&quot;291dp&quot;<br>        android:layout_height=&quot;99dp&quot;<br>        android:layout_marginBottom=&quot;8dp&quot;<br>        android:layout_marginEnd=&quot;8dp&quot;<br>        android:layout_marginStart=&quot;8dp&quot;<br>        android:layout_marginTop=&quot;8dp&quot;<br>        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>        app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>        app:layout_constraintHorizontal_bias=&quot;0.506&quot;<br>        app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>        app:layout_constraintTop_toBottomOf=&quot;@+id/textview&quot;<br>        app:layout_constraintVertical_bias=&quot;0.277&quot;<br>        app:srcCompat=&quot;@mipmap/ic_launcher_round&quot; </strong>/&gt;<br><br>    &lt;<strong>Button<br>        android:id=&quot;@+id/button&quot;<br>        android:layout_width=&quot;294dp&quot;<br>        android:layout_height=&quot;55dp&quot;<br>        android:layout_marginEnd=&quot;8dp&quot;<br>        android:layout_marginStart=&quot;8dp&quot;<br>        android:layout_marginTop=&quot;52dp&quot;<br>        android:text=&quot;Button&quot;<br>        app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>        app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>        app:layout_constraintTop_toBottomOf=&quot;@+id/imageView&quot; </strong>/&gt;<br><br>&lt;/<strong>android.support.constraint.ConstraintLayout</strong>&gt;</pre><p>Final Look Kotlin Activity</p><pre><strong>package </strong>com.mrkotlin.mrkotlincustomtoast<br><br><strong>import </strong>android.graphics.Color<br><strong>import </strong>android.os.Bundle<br><strong>import </strong>android.support.v4.content.ContextCompat<br><strong>import </strong>android.support.v7.app.AppCompatActivity<br><strong>import </strong>android.view.View<br><strong>import </strong>android.widget.Toast<br><strong>import </strong>kotlinx.android.synthetic.main.activity_main.*<br><br><strong>class </strong>MainActivity : AppCompatActivity() {<br><br>    <strong>override fun </strong>onCreate(savedInstanceState: Bundle?) {<br>        <strong>super</strong>.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_main</em>)<br><br>        textview.setTextColor(Color.<em>RED</em>)<br>        textview.<em>text </em>= <strong>&quot;this text setted programatically&quot;<br><br>        </strong>imageView.setImageDrawable(ContextCompat.getDrawable(<strong>this</strong>@MainActivity, android.R.drawable.<em>ic_menu_share</em>))<br>        imageView.setBackgroundColor(Color.<em>GREEN</em>)<br><br>        button.setOnClickListener <strong>{<br>            </strong>Toast.makeText(<strong>this</strong>@MainActivity, <strong>&quot;${</strong>button.<em>text</em><strong>} clicked &quot;</strong>, Toast.<em>LENGTH_LONG</em>).show()<br>            button.setBackgroundColor(Color.<em>RED</em>)<br>        <strong>}<br><br>    </strong>}<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c23e31b38be" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>