<?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 Rasul Aghakishiyev on Medium]]></title>
        <description><![CDATA[Stories by Rasul Aghakishiyev on Medium]]></description>
        <link>https://medium.com/@agarasul?source=rss-d6e17d68032d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*H1bReYgOd3-fhGeXfkfWSw.jpeg</url>
            <title>Stories by Rasul Aghakishiyev on Medium</title>
            <link>https://medium.com/@agarasul?source=rss-d6e17d68032d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 05:10:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@agarasul/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[Teezy — Dental History Tracker]]></title>
            <link>https://agarasul.medium.com/teezy-dental-history-tracker-a62ac3c06695?source=rss-d6e17d68032d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a62ac3c06695</guid>
            <category><![CDATA[dental-care]]></category>
            <category><![CDATA[dentistry]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[healthcare]]></category>
            <category><![CDATA[health]]></category>
            <dc:creator><![CDATA[Rasul Aghakishiyev]]></dc:creator>
            <pubDate>Sat, 04 Jan 2025 18:35:18 GMT</pubDate>
            <atom:updated>2025-01-04T18:39:13.520Z</atom:updated>
            <content:encoded><![CDATA[<h3>Teezy Makes Managing Your Dental Health Surprisingly Simple</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uIAR2oiqHOGplGRV67hA7w.png" /></figure><p>Link to the app: <a href="https://apps.apple.com/us/app/teezy-dental-care/id6740062974">https://apps.apple.com/us/app/teezy-dental-care/id6740062974</a></p><p>Like many people, I like to track stuff and keep track of progress.</p><p>I went to different dental clinics at different times (like all people?). When you change clinics, all history stays with them and clinics don’t share that history with each other.</p><p>At some point, I started taking notes on visits. They were just short notes like “09.09.24, 16 had a filling replaced”, “22.05.24, had a cleaning” etc. Thanks to them it was possible to find out when I was last at the dentist and what I had done.</p><p>The records became more 🥲, it became more difficult to dig through them and the idea came up — an application with a visual scheme of teeth in which you can record the results of visits.</p><p>When it came time to choose an idea to develop, this one seemed interesting. I dreamed about how many features could be realized in such an application and started working on it.</p><p>Meet Teezy!</p><p>Key features:</p><ul><li>Track Tooth Health: Add detailed records for individual teeth or monitor your overall dental condition.</li><li>Manage Appointments: Schedule dentist visits, set reminders, and receive notifications so you never miss an appointment.</li><li>Teeth Map: Visualize your teeth with detailed mapping systems that make it easy to understand and analyze your dental health.</li><li>Multiple Profiles: Manage dental records for your entire family or multiple individuals with ease.</li></ul><p>Link to the app: <a href="https://apps.apple.com/us/app/teezy-dental-care/id6740062974">https://apps.apple.com/us/app/teezy-dental-care/id6740062974</a></p><p>I would be super happy to see your feedback and thoughts!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a62ac3c06695" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build your components the right way with Jetpack Compose]]></title>
            <link>https://proandroiddev.com/build-your-components-the-right-way-with-jetpack-compose-f3a2c96b7616?source=rss-d6e17d68032d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3a2c96b7616</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Rasul Aghakishiyev]]></dc:creator>
            <pubDate>Fri, 08 Nov 2024 17:48:50 GMT</pubDate>
            <atom:updated>2024-11-08T17:48:50.128Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZcecKxtthrK1OdFOCWgyVw.png" /></figure><p>Jetpack Compose is Google’s modern toolkit for building native Android UI. Designed to simplify and accelerate UI development, it uses a declarative approach, allowing developers to directly define how the UI should look and respond to data changes. Unlike traditional XML-based layouts, Jetpack Compose lets you write UI code in Kotlin, which leads to more concise, readable, and maintainable code.</p><p>One of the standout features of Jetpack Compose is its composable functions, reusable components that manage their own state, handle UI logic, and can be combined to create complex layouts.</p><p>When building components, think about where and how they might be reused. Create generic composables (like buttons, cards, and text fields) that aren’t tied to specific screen logic. Make them adaptable by allowing customizable parameters, such as colors, shapes, or actions, so they can serve multiple purposes across your app.</p><p>Here are some examples of <strong>bad</strong> composables.</p><pre>data class Person(<br>    val id: String,<br>    val name: String,<br>    val surname: String,<br>    val age: Int,<br>    val createdAt: Long,<br>    val email: String,<br>    val phone: String,<br>    val photo: String,<br>    val likesCount: Int<br>)<br><br>@Composable<br>fun PersonLikeCountCell(person: Person) {<br>    Row {<br>        Text(text = person.name)<br>        Icon(imageVector = Icons.Default.Star, contentDescription = null)<br>        Text(text = &quot;${person.likesCount} likes&quot;)<br>    }<br>}</pre><p>Why is this composable function bad? Because we are passing the Person object here, while we need name and likesCountof Person. This makes our composables less reusable. So if we will have another model and we want to use this function, we will not be able to do that. Let’s rewrite our function to make it more reusable</p><pre>@Composable<br>fun PersonLikeCountCell(name: String, likesCount: Int) {<br>    Row {<br>        Text(text = name)<br>        Icon(imageVector = Icons.Default.Star, contentDescription = null)<br>        Text(text = &quot;$likesCount likes&quot;)<br>    }<br>}</pre><p>Now our function takes two parameters: name and likesCount. This means that we can reuse it anywhere just passing these two parameters. Our function became independent,</p><p>You should remember that your composables shouldn’t rely on data models everywhere where this possible. This will also prevent component from unnecessary recompositions.</p><p>Another thing that many engineers do wrong, is putting state in wrong place. Here is an example</p><pre>@Composable<br>fun UserDetailsPage() {<br>    var bgColor by remember {<br>        mutableStateOf(Color.Red)<br>    }<br>    Column(<br>        modifier = Modifier.background(bgColor)<br>    ) {<br>        Button(onClick = {<br>            bgColor = Color.Blue<br>        }) {<br>            Text(text = &quot;Change color&quot;)<br>        }<br>    }<br>}</pre><p>What is wrong with this composable?</p><p>The main issue here is that when we change the color system will start the composition and layout phases for our Column . So if you want only change the color of component instead of backround modifier we should use drawBehind modifier.</p><pre>@Composable<br>fun UserDetailsPage() {<br>    var bgColor by remember {<br>        mutableStateOf(Color.Red)<br>    }<br>    Column(<br>        modifier = Modifier.drawBehind { <br>            drawRect(bgColor)<br>        }<br>    ) {<br>        Button(onClick = {<br>            bgColor = if (bgColor == Color.Red) Color.Blue else Color.Red<br>        }) {<br>            Text(text = &quot;Change color&quot;)<br>        }<br>    }<br>}</pre><p>Now our system will skip the composition and layout phases, and will go straight to the draw phase.</p><h4>Conclusion</h4><p>In summary, following best practices in Jetpack Compose helps create efficient, responsive, and maintainable Android apps. By managing state wisely, structuring composables effectively, and optimizing performance, developers can deliver a seamless user experience.</p><p>Feel free to follow me on Twitter and don’t hesitate to ask questions related to Jetpack Compose.</p><p>Twitter: <a href="https://twitter.com/a_rasul98">https://twitter.com/a_rasul98</a></p><p>Also check out my other posts related to Jetpack Compose:</p><p><a href="https://agarasul.medium.com/">Rasul Aghakishiyev - Medium</a></p><p>Thanks for reading and see you later!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3a2c96b7616" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/build-your-components-the-right-way-with-jetpack-compose-f3a2c96b7616">Build your components the right way with Jetpack Compose</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[Free hand draw polygon in Google Maps Compose. Part 2]]></title>
            <link>https://proandroiddev.com/free-hand-draw-polygon-in-google-maps-compose-part-2-4090cbaf4015?source=rss-d6e17d68032d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4090cbaf4015</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[google-maps]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Rasul Aghakishiyev]]></dc:creator>
            <pubDate>Wed, 13 Dec 2023 16:57:34 GMT</pubDate>
            <atom:updated>2024-01-02T21:51:14.269Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cxb2kjoUpCCqlnIP6MjGzQ.png" /></figure><p>In the previous part we learned how to draw in Jetpack Compose using Canvas API. If you didn’t read it yet, here is the link</p><p><a href="https://agarasul.medium.com/free-hand-draw-polygon-in-google-maps-compose-8332e0f3ab69">Free hand draw polygon in Google Maps Compose</a></p><p>Today we will learn how select area in google maps using free hand drawn polygon.</p><p>First of all we need add Google Maps dependencies.</p><pre>implementation(&quot;com.google.maps.android:maps-compose:2.11.4&quot;)<br>implementation(&quot;com.google.android.gms:play-services-maps:18.2.0&quot;)</pre><p>I will not deep dive into this, you can read more about Maps Compose here:</p><p><a href="https://developers.google.com/maps/documentation/android-sdk/maps-compose">Maps Compose Library | Maps SDK for Android | Google for Developers</a></p><p>Now let’s create our map composable</p><pre>@Composable<br>fun MyMap(points : List&lt;Point&gt;) {<br>    val losAngeles = LatLng(34.052235, -118.243683)<br>    val cameraPositionState = rememberCameraPositionState {<br>        position = CameraPosition.fromLatLngZoom(losAngeles, 10f)<br>    }<br>    GoogleMap(<br>        modifier = Modifier<br>            .fillMaxSize(),<br>        cameraPositionState = cameraPositionState<br>    ){<br>        <br>    }<br>}</pre><p>There isn’t too much things to describe.</p><ol><li><strong>cameraPositionState —</strong> used to move camera on the map</li><li><strong>points — </strong>we will use to draw polygon on the map and later we transform them into real world coordinates.</li></ol><p>To transform points into real world coordinates we have class <strong>Projection</strong>, which has method <strong>fromScreenLocation</strong> n in Google Maps SDK</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_pRwRfgXQQZb9MBD80TbnQ.png" /></figure><p>We will use this function to transform our screen locations to geographic locations.</p><p>We can access to projection from cameraPositionState</p><pre>@Composable<br>fun MyMap(points : List&lt;Point&gt;) {<br>    val losAngeles = LatLng(34.052235, -118.243683)<br>    val cameraPositionState = rememberCameraPositionState {<br>        position = CameraPosition.fromLatLngZoom(losAngeles, 10f)<br>    }<br>    GoogleMap(<br>        modifier = Modifier<br>            .fillMaxSize(),<br>        cameraPositionState = cameraPositionState<br>    ){<br>       cameraPositionState.projection?.let { projection -&gt;<br><br>       }<br>    }<br>}</pre><p>We also need a state variable to store our transformed points</p><pre>// We will store our geo points there. We will use them to draw polygon on map<br>var geoPoints by remember { mutableStateOf(listOf&lt;LatLng&gt;()) }</pre><p>Now let’s start to transform our coordinates using projection</p><pre>cameraPositionState.projection?.let { projection -&gt;<br>    geoPoints = points.map { <br>         projection.fromScreenLocation(it)<br>    }<br>}</pre><p>You can see, it’s super easy to use.</p><p>In order to show polygon on the map, we can use Polygon composable which provided by Maps Compose SDK. So now our code will look like this</p><pre>@OptIn(MapsComposeExperimentalApi::class)<br>@Composable<br>fun MyMap(points: List&lt;Point&gt;) {<br>    val losAngeles = LatLng(34.052235, -118.243683)<br>    val cameraPositionState = rememberCameraPositionState {<br>        position = CameraPosition.fromLatLngZoom(losAngeles, 10f)<br>    }<br><br>    var geoPoints by remember { mutableStateOf(listOf&lt;LatLng&gt;()) }<br><br>    GoogleMap(<br>        modifier = Modifier<br>            .fillMaxSize(),<br>        cameraPositionState = cameraPositionState<br>    ) {<br>        cameraPositionState.projection?.let { projection -&gt;<br>            geoPoints = points.map { <br>               projection.fromScreenLocation(it)<br>            }<br>        }<br><br>        if (geoPoints.isNotEmpty()) {<br>            Polygon(<br>                points = geoPoints,<br>                fillColor = Color.Black.copy(alpha = 0.4f)<br>            )<br>        }<br>    }<br>}</pre><p>That’s all on map part. Now we should somehow pass points to our map composable. Let’s jump quickly to our MapDrawer composable. Now it looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c3a26bc614819273be7ca8cdb5e5b30/href">https://medium.com/media/5c3a26bc614819273be7ca8cdb5e5b30/href</a></iframe><p>First, we need add some variable to store our coordinates. Let’s modify our awaitEachGesture function body and also, we need add callback which will be trigger when drawing finished.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bfc722e09bdc3463250178c6f292be2a/href">https://medium.com/media/bfc722e09bdc3463250178c6f292be2a/href</a></iframe><p>Now we should put these 2 composable together:</p><pre>@Composable<br>fun MapsDrawerPage() {<br>    var points by remember { mutableStateOf(listOf&lt;Point&gt;()) }<br>    Box(modifier = Modifier.fillMaxSize()) {<br>        MyMap(points = points)<br>        MapDrawer(<br>            onDrawingEnd = {<br>                points = it<br>            }<br>        )<br>    }<br>}</pre><p>Let’s see how this looks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*QaP_cHQ8HQdSZ9tV5Jkglw.gif" /></figure><p>Now the final part get bounds of this polygon. For this should use <strong>LatLngBounds.Builder</strong> class. Let’s do some modification</p><pre>cameraPositionState.projection?.let { projection -&gt;<br>    geoPoints = if (points.isEmpty()) {<br>        emptyList()<br>    } else {<br>        val boundsBuilder = LatLngBounds.Builder()<br>        points.map {<br>            val latLng = projection.fromScreenLocation(<br>                Point(it.x, it.y)<br>            )<br>            boundsBuilder.include(latLng)<br>            latLng<br>        }<br>    }<br>}</pre><p>We added empty check because, boundsBuilder.build() will raise an exception if we it don’t have any locations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*bF4z3TkD5KolFCgYFOtv9Q.gif" /></figure><p>The full code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b657922f88ba541b2dedaac6c25a3404/href">https://medium.com/media/b657922f88ba541b2dedaac6c25a3404/href</a></iframe><h4>Conclusion</h4><p>Today learned how to draw polygon on Canvas and transform them into geographic coordinates using Maps Compose SDK.</p><p>Feel free to follow me on Twitter and don’t hesitate to ask questions related to Jetpack Compose.</p><p>Twitter: <a href="https://twitter.com/a_rasul98">https://twitter.com/a_rasul98</a></p><p>Also check out my other post related to Jetpack Compose:</p><p><a href="https://agarasul.medium.com/">Rasul Aghakishiyev - Medium</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4090cbaf4015" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/free-hand-draw-polygon-in-google-maps-compose-part-2-4090cbaf4015">Free hand draw polygon in Google Maps Compose. Part 2</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[Free hand draw polygon in Google Maps Compose]]></title>
            <link>https://proandroiddev.com/free-hand-draw-polygon-in-google-maps-compose-8332e0f3ab69?source=rss-d6e17d68032d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8332e0f3ab69</guid>
            <dc:creator><![CDATA[Rasul Aghakishiyev]]></dc:creator>
            <pubDate>Tue, 12 Dec 2023 20:22:19 GMT</pubDate>
            <atom:updated>2023-12-24T01:19:58.740Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cxb2kjoUpCCqlnIP6MjGzQ.png" /></figure><h3>Free hand draw polygon in Google Maps Compose. Part 1</h3><p>I work on a real estate app that was written in Kotlin with XML with many custom animations and views. A few months ago, we decided to migrate our application to Jetpack Compose. In our real estate app, we have a unique functionality that allows users to draw specific areas on the map, restricting ads to only those within the selected region. In the previous version of the app, we utilized a Custom View to draw polygons and then transformed screen coordinates to map coordinates.</p><p>In this post, I’ll demonstrate how we implemented this feature in Jetpack Compose. It will be a simple view that only can draw lines and nothing else, we will Canvas composable for this.</p><pre>@Composable<br>fun MapDrawer() {<br>    Canvas(<br>        modifier = Modifier.fillMaxSize(),<br>        onDraw = {<br>            <br>        }<br>    )<br>}</pre><blockquote><strong><em>onDraw</em></strong><em> - lambda that will be called to perform drawing</em></blockquote><p>In onDraw lambda we can call various method to draw. There are some of them:</p><pre>drawPath()<br>drawLine()<br>drawArc()<br>drawCircle()<br>drawRect()</pre><p>As you can see it’s pretty similar to Canvas that is used in XML based views.</p><p>You can read more about drawing:</p><p><a href="https://developer.android.com/jetpack/compose/graphics/draw/overview">Graphics in Compose | Jetpack Compose | Android Developers</a></p><p>For now, our attention won’t be spread across all features. Instead, we’ll exclusively focus on the implementation of drawPath in our example.</p><p>The next step involves dealing with touch events within our Canvas composable. To address this, we&#39;ll leverage the pointerInput modifier, providing us with the capability to effectively handle all events taking place within our composable.</p><pre>fun Modifier.pointerInput(<br>    key1: Any?,<br>    block: suspend PointerInputScope.() -&gt; Unit<br>): Modifier = this then SuspendPointerInputElement(<br>    key1 = key1,<br>    pointerInputHandler = block<br>)</pre><p>It receives only 2 parameters: key and block. For key we will just pass Unit. So we have something like this</p><pre>@Composable<br>fun MapDrawer() {<br>    Canvas(<br>        modifier = Modifier<br>            .fillMaxSize()<br>            .pointerInput(Unit){<br>                               <br>            },<br>        onDraw = {<br><br>        }<br>    )<br>}</pre><p>To actively handle events, we need to invoke the awaitEachGesture function. This is a <strong>suspend</strong> function that runs in a loop while the composable is active. Within this function, we use awaitPointerEvent to manage the current event. It&#39;s essential to call this function inside a while loop to continuously receive events.</p><p>So we will have something like this:</p><pre>@Composable<br>fun MapDrawer() {<br>    Canvas(<br>        modifier = Modifier<br>            .fillMaxSize()<br>            .pointerInput(Unit) {<br>                awaitEachGesture {<br>                    do {<br>                        val event: PointerEvent = awaitPointerEvent()<br>                    } while (event.changes.any { it.pressed })<br>                }<br>            },<br>        onDraw = {}<br>    )<br>}</pre><p>Our <strong>event</strong> variable contains lots of information about happened event. But we will use <strong>changes</strong> property to get information that we need to draw.</p><pre>@Composable<br>fun MapDrawer() {<br>    Canvas(<br>        modifier = Modifier<br>            .fillMaxSize()<br>            .pointerInput(Unit) {<br>                awaitEachGesture {<br>                    do {<br>                        val event: PointerEvent = awaitPointerEvent()<br>                        event.changes.forEach { changes -&gt;<br>                            // contains coordinates where event happened<br>                            val position = changes.position<br>                        }<br>                    } while (event.changes.any { it.pressed })<br>                }<br>            },<br>        onDraw = {}<br>    )<br>}</pre><p>Now let’s create a state object which will contains information about touch event.</p><pre>enum class DrawerMotionEvent { idle, down, up, move }<br><br>data class MapPolygonState(<br>    val currentPosition: Offset = Offset.Unspecified,<br>    val event: MotionEvent = MotionEvent.idle<br>)</pre><p>Let’s update our composable:</p><pre>@Composable<br>fun MapDrawer() {<br>    val path = remember { Path() }<br>    var state by remember { mutableStateOf(MapPolygonState()) }<br>    Canvas(<br>        modifier = Modifier<br>            .fillMaxSize()<br>            .pointerInput(Unit) {<br>                awaitEachGesture {<br>                    do {<br>                        val event: PointerEvent = awaitPointerEvent()<br>                        event.changes.forEach { changes -&gt;<br>                            // Updates state with new event and position<br>                            state = state.copy(<br>                                currentPosition = changes.position,<br>                                event = DrawerMotionEvent.move<br>                            )<br>                        }<br>                    } while (event.changes.any { it.pressed })<br>                }<br>            },<br>        onDraw = {}<br>    )<br>}</pre><p>In the code, we update our state object every time when new event handled, which will initiate recomposition of our composable on every touch. We also have path variable here which will holds all points.</p><p>Now let’s jump on to <strong>onDraw</strong> block. Here we will add points to our path and draw it on canvas. We just need to draw our path</p><pre>onDraw = {<br>    when (state.event) {<br>        DrawerMotionEvent.idle -&gt; Unit<br>        DrawerMotionEvent.up, DrawerMotionEvent.move -&gt; path.lineTo(<br>            state.currentPosition.x,<br>            state.currentPosition.y<br>        )<br>        DrawerMotionEvent.down -&gt; path.moveTo(state.currentPosition.x, state.currentPosition.y)<br>    }<br>    drawPath(<br>        path = path,<br>        brush = brush,<br>        style = Stroke(width = 5f)<br>    )<br>}</pre><p>Our composable will looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12232fbab311d896273637d04b52b85c/href">https://medium.com/media/12232fbab311d896273637d04b52b85c/href</a></iframe><p>And here is the example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*8F5njXGndFimG7A_fgdhcg.gif" /></figure><p>As you can see we have straight line drawn from top left corner. That’s because Path always start from (0,0) point. To fix this we can add this in our <strong>awaitEachGesture</strong> function before<strong> </strong>our loop<strong> </strong>block</p><pre>awaitPointerEvent().changes.first().also { changes -&gt;<br>    val position = changes.position<br>    state = state.copy(<br>        currentPosition = position,<br>        event = DrawerMotionEvent.down<br>    )<br>}</pre><p>By adding this before entering the loop, we ensure that the starting point of the path corresponds to the initial touch position. This adjustment sets the path to begin at the touch point, providing a more intuitive drawing experience.</p><p>So on our first touch we will move our path to correct location. Now let’s try again</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*jMSho0MjCNnQDmjaTTpiZg.gif" /></figure><p>Yay, we draw in Jetpack Compose!</p><p>Here is the full code of Composable:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c3a26bc614819273be7ca8cdb5e5b30/href">https://medium.com/media/5c3a26bc614819273be7ca8cdb5e5b30/href</a></iframe><p>That wraps up the initial part of our tutorial. Today, we covered the fundamentals of drawing on the Canvas using its methods and also handling touch events in Jetpack Compose.</p><p>In the next part our journey will shift towards the transformation of our drawings into Google Maps polygons and extracting their real coordinate bounds.</p><p>Part 2:</p><p><a href="https://agarasul.medium.com/free-hand-draw-polygon-in-google-maps-compose-part-2-4090cbaf4015">Free hand draw polygon in Google Maps Compose. Part 2</a></p><p>Feel free to follow me on Twitter and don’t hesitate to ask questions related to Jetpack Compose.</p><p>Twitter: <a href="https://twitter.com/a_rasul98">https://twitter.com/a_rasul98</a></p><p>Also check out my other post related to Jetpack Compose:</p><p><a href="https://agarasul.medium.com/">Rasul Aghakishiyev - Medium</a></p><p>Thanks for reading and see you later!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8332e0f3ab69" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/free-hand-draw-polygon-in-google-maps-compose-8332e0f3ab69">Free hand draw polygon in Google Maps Compose</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[State in Jetpack Compose]]></title>
            <link>https://proandroiddev.com/state-in-jetpack-compose-f2c0dc20d442?source=rss-d6e17d68032d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2c0dc20d442</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[jetpack]]></category>
            <dc:creator><![CDATA[Rasul Aghakishiyev]]></dc:creator>
            <pubDate>Wed, 04 Aug 2021 06:56:22 GMT</pubDate>
            <atom:updated>2022-10-02T15:08:57.126Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ogLoBDSPEf2w_F0ZcYeZQ.png" /></figure><p>All Android apps display state to the user. A few examples of state in Android apps:</p><ul><li>Show AlertDialog when some work is done</li><li>All animations that appears in application</li><li>Open or close NavigationDrawer or BottomSheet</li></ul><p>Today we will learn how to store our app state in Jetpack Compose.</p><p>As you know Jetpack Compose is a declarative framework that uses composable functions to render UI. This means that to update the state of an app we should call a composable function with new arguments. For example, we need to show update the greeting text according to users input</p><pre>@Composable<br>fun GreetingBox() {<br>    <em>Column </em><strong>{<br>        </strong><em>Text</em>(text = &quot;Hello, &quot;)<br>        <em>OutlinedTextField</em>(value = &quot;&quot;, onValueChange = <strong>{<br>            <br>        }</strong>)<br>    <strong>}<br></strong>}</pre><p>So if we run this composable, we will see that we cannot write in our TextField.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*J-1kYqD6tvANn2q489spFw.gif" /></figure><p>That’s because we set the constant value to TextField and on every recomposition, our text will be empty. You maybe think that we can create some variable that will store our text and then pass to the TextField value. Let’s try this and see what happens.</p><pre>@Composable<br>fun GreetingBox() {<br>    var username = &quot;&quot;<br>    <em>Column </em><strong>{<br>        </strong><em>Text</em>(text = &quot;Hello, $username&quot;)<br>        <em>OutlinedTextField</em>(value = username, onValueChange = <strong>{<br>            </strong>username = <strong>it<br>        }</strong>)<br>    <strong>}<br></strong>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*J-1kYqD6tvANn2q489spFw.gif" /></figure><p>The result was the same. Jetpack Compose doesn’t recompose our function with a new value because it didn’t know that state changed. For this purpose, we have mutableStateOf that converts our value to the state that Jetpack Compose will handle.</p><pre>@Composable<br>fun GreetingBox() {<br>    var username by <em>mutableStateOf</em>(&quot;&quot;)<br><br>    <em>Column </em><strong>{<br>        </strong><em>Text</em>(text = &quot;Hello, $username&quot;)<br>        <em>OutlinedTextField</em>(value = username, onValueChange = <strong>{<br>            </strong>username = <strong>it<br>        }</strong>)<br>    <strong>}<br></strong>}</pre><p>If write code like this android studio will show warning:</p><blockquote>Creating a state object during composition without using remember</blockquote><p>As we mentioned Jetpack Compose recompose functions whenever the state changes. This means that the username object will be recreated on every recomposition. In our case when the value in TextField changes and Jetpack Compose recompose our GreetingBox.</p><p>To avoid this problem we need to store the value somewhere that is free from recomposition which will save its state despite recomposition. For this purpose in Jetpack Compose, we have remember. It will store the value during the composition.</p><p>After this updates our code will look like this:</p><pre>@Composable<br>fun GreetingBox() {<br>    var username by <em>remember </em><strong>{<br>        </strong><em>mutableStateOf</em>(&quot;&quot;)<br>    <strong>}<br>    </strong><em>Column </em><strong>{<br>        </strong><em>Text</em>(text = &quot;Hello, &quot;)<br>        <em>OutlinedTextField</em>(value = username, onValueChange = <strong>{<br>            </strong>username = <strong>it<br>        }</strong>)<br>    <strong>}</strong></pre><p>And now whenever users input change, our username will notify the system that its state changed and this composable should be recomposed with a new value. As the result, our username variable always will be with the latest input that the user entered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*7MpvSP7ggWXYJiFTuHKJ0A.gif" /></figure><h3>Additionally</h3><p>To store our data, we can also use ViewModel from Architecture Components. ViewModels also free from the lifecycle of Jetpack Compose and will be a perfect fit for this. Now our code looks like this.</p><pre>class GreetingViewModel : ViewModel() {<br>    private val _userName = MutableLiveData(&quot;&quot;)<br>    val userName: LiveData&lt;String&gt; = _userName<br>    fun onNameChange(input: String) {<br>        _userName.<em>value </em>= input<br>    }<br>}<br><br><br>@Composable<br>fun GreetingBox(<br>    vm: GreetingViewModel = <em>viewModel</em>()<br>) {<br>    val username = vm.userName.<em>observeAsState</em>()<br>    <em>Column </em><strong>{<br>        </strong><em>Text</em>(text = &quot;Hello, ${username.value}&quot;)<br>        <em>OutlinedTextField</em>(<br>            value = username.value!!,<br>            onValueChange = vm::onNameChange<br>        )<br>    <strong>}<br></strong>}</pre><p>Run code and we will see that everything also works fine:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*7MpvSP7ggWXYJiFTuHKJ0A.gif" /></figure><h3>Conclusion</h3><p>Today we learned to how learned how to save states in Jetpack Compose. <br>To store values in Composable functions free from recomposition we always must use remember. Also, ViewModel will be the perfect choice to save data because it is attached to an Activity lifecycle instead of composable</p><p>Feel free to follow me on Twitter and don’t hesitate to ask questions related to Jetpack Compose.</p><p>Twitter : <a href="https://twitter.com/a_rasul98">https://twitter.com/a_rasul98</a></p><p>Thanks for reading, and see you later!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2c0dc20d442" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/state-in-jetpack-compose-f2c0dc20d442">State in Jetpack Compose</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[Complex UI in Jetpack Compose]]></title>
            <link>https://proandroiddev.com/complex-ui-in-jetpack-compose-bba76e705ade?source=rss-d6e17d68032d------2</link>
            <guid isPermaLink="false">https://medium.com/p/bba76e705ade</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Rasul Aghakishiyev]]></dc:creator>
            <pubDate>Fri, 23 Apr 2021 09:31:04 GMT</pubDate>
            <atom:updated>2021-04-23T12:07:25.489Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u56IHLNYmjaa-MYU6ToDnA.png" /></figure><p>Jetpack Compose provides many tools for creating UI. With Jetpack Compose you can easily create an MVP of your project, and see how it looks. For example, to create a list in Android in the usual way, we should use RecyclerView. And of course, we need to create an adapter and view holder to manage items in RecyclerView. In Jetpack Compose we can do it easily.</p><pre>@Composable<br>fun NewsList() {<br>    <em>LazyColumn </em><strong>{<br>        </strong><em>items</em>(<em>rows</em>) <strong>{ </strong>item <strong>-&gt;<br>            </strong><em>Text</em>(<br>                modifier = Modifier<br>                    .<em>height</em>(80.<em>dp</em>),<br>                text = item<br>            )<br>        <strong>}<br>    }<br></strong>}</pre><p>And that’s all. No need for an adapter, view holder, etc. <br>LazyColumn is used when you want to create a vertical list. To create horizontal we just replace our LazyColumn with LazyRow and our list become horizontal</p><pre>@Composable<br>fun NewsList() {<br>    <em>LazyRow </em><strong>{<br>        </strong><em>items</em>(<em>rows</em>) <strong>{ </strong>item <strong>-&gt;<br>            </strong><em>Text</em>(<br>                modifier = Modifier<br>                    .<em>height</em>(80.<em>dp</em>),<br>                text = item<br>            )<br>        <strong>}<br>    }<br></strong>}</pre><p>If you want to get an index of the item, replace <em>items </em>to<em> </em><em>itemsIndexed </em>and you will access to index of the current item</p><pre><em>itemsIndexed</em>(<em>rows</em>) <strong>{ </strong>index, item <strong>-&gt;<br>    </strong><em>Text</em>(<br>        modifier = Modifier<br>            .<em>height</em>(80.<em>dp</em>),<br>        text = item<br>    )<br><strong>}</strong></pre><p>What if we want to create a nested list. That contains both vertical and horizontal items. Of course, for this purpose, we can use LazyVerticalGrid.</p><pre><em>LazyVerticalGrid</em>(cells = GridCells.Fixed(10)) <strong>{<br>    </strong><em>itemsIndexed</em>(<em>rows</em>) <strong>{ </strong>row, item<strong>-&gt;<br>        </strong><em>Text</em>(<br>            modifier = Modifier<br>                .<em>height</em>(80.<em>dp</em>),<br>            text = item<br>        )<br>    <strong>}<br>}</strong></pre><p>But there are a couple of problems with the solution. First, is <em>LazyVerticalGrid </em>still annotated as ExperimentalFoundationApi . The second one is it allows your grid to scroll only vertically. And the third one is it always fits the screen width. So for example, if you want to have 8 columns, <em>LazyVerticalGrid </em>tries to fit all of them into the screen. Here is an example of its work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*cbdFEVYUP5_zI750RwJVnQ.png" /></figure><p>I think you will agree with me, that it looks a little bit weird, instead of fitting all items into the screen, I want to be able to scroll my grid horizontally to see all items. To make this will use components that we used before LazyRow and LazyColumn. The mix of these two components allows us to create a complex scrollable grid with minimal effort. Let’s start!</p><p>First, we need to create LazyColumn to make our items scrollable vertically. But at this time our item of LazyColumn will be LazyRow. I added some modifiers to the Text component to make the grid a little bit beautiful.</p><pre><em>LazyColumn </em><strong>{<br>    </strong><em>itemsIndexed</em>(rows) <strong>{ </strong>index, row <strong>-&gt;<br>        </strong><em>LazyRow </em><strong>{<br>            </strong><em>itemsIndexed</em>(columns) <strong>{ </strong>index, column <strong>-&gt;<br>                </strong><em>Text</em>(<br>                    modifier = Modifier<br>                        .<em>padding</em>(8.<em>dp</em>)<br>                        .<em>background</em>(Color.Red)<br>                        .<em>width</em>(100.<em>dp</em>)<br>                        .<em>height</em>(100.<em>dp</em>),<br>                    textAlign = TextAlign.<em>Center</em>,<br>                    color = Color.White,<br>                    text = &quot;Row $row Column = $column&quot;<br>                )<br>            <strong>}<br>        }<br><br>    }<br>}</strong></pre><p>rows — in an array of strings with size of 10</p><p>column — in an array of strings with size of 10</p><p>So we will have a grid with 10 rows and with the same size columns</p><p>And we run our code we will see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*Dc0VY0SQNpICyIG_lWVGkw.gif" /></figure><p>Using this solution we achieve some benefits:</p><ol><li>More customization opportunities. Ability to change every item in grid or change items only on specific column or row</li><li>Full control of our grid.</li><li>Infinite scroll in both directions</li></ol><h3><strong>Conclusion</strong></h3><p>Jetpack Compose provides many tools for creating complex UI. Today we learned the ways to create a grid in Jetpack Compose. If you want to create a simple grid without features such as a horizontal scroll or an infinitive scroll you should use LazyVerticalGrid. Otherwise, I recommend you to use a mix of LazyRow and LazyColumn for these purposes.</p><p>Feel free to follow me on Twitter and don’t hesitate to ask questions related to Jetpack Compose.</p><p>Twitter : <a href="https://twitter.com/a_rasul98">https://twitter.com/a_rasul98</a></p><p>Thanks for reading, and see you later!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bba76e705ade" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/complex-ui-in-jetpack-compose-bba76e705ade">Complex UI in Jetpack Compose</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[Bottom Sheet in Jetpack Compose]]></title>
            <link>https://proandroiddev.com/bottom-sheet-in-jetpack-compose-c8ab7a297aac?source=rss-d6e17d68032d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8ab7a297aac</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Rasul Aghakishiyev]]></dc:creator>
            <pubDate>Tue, 02 Mar 2021 19:49:07 GMT</pubDate>
            <atom:updated>2021-03-03T15:59:59.415Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0HcUTWdqQ7RTaWCRe4Askw.png" /></figure><p>As we can see Jetpack Compose grows like crazy. Last week they announced that Jetpack Compose went to Beta! Today we will talk about how to create bottom sheets in Jetpack Compose.</p><p>To implement the bottom sheet, we need to use <em>BottomSheetScaffold.</em> It was annotated as an ExperimentalApi, so to use it we need to add @ExperimentalMaterialApi annotation to the method where we will use.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35f148369ff606d220ba50ecee0e1833/href">https://medium.com/media/35f148369ff606d220ba50ecee0e1833/href</a></iframe><p>Let’s look at this code block closely.</p><p>First, we define bottomSheetScaffoldState which will hold the state of BottomSheetScaffold. In turn it holds drawerState, bottomSheetState<em>, </em>snackbarHostState<em>. </em>In this tutorial, we focus only on bottomSheetState</p><p>sheetContent — defines the content of our Bottom Sheet. You put any composable you want.</p><p>sheetPeekHeight — sets the peek height of the Bottom Sheet. We will use 0.dp to hide the Bottom Sheet when the app starts.</p><p>So to interact with Bottom Sheet, we just must use these methods:</p><p>bottomSheetScaffoldState.bottomSheetState.expand() — to expand</p><p>bottomSheetScaffoldState.bottomSheetState.collapse() — to collapse</p><p>But these methods are <em>suspend</em> functions and that’s why they must be used in CoroutineScope.</p><p>For this purpose we can use rememberCoroutineScope to create coroutineScope .</p><pre>coroutineScope.launch {<br>    if (bottomSheetScaffoldState.bottomSheetState.isCollapsed) {<br>        bottomSheetScaffoldState.bottomSheetState.expand()<br>    } else {<br>        bottomSheetScaffoldState.bottomSheetState.collapse()<br>    }<br>}</pre><p>Now run our app and see what happens:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*JaivQzM3AlqY03jRzohLSQ.gif" /></figure><h3>Conclusion</h3><p>Today we used <em>BottomSheetScaffold </em>to create a Scaffold template with a Bottom Sheet. It allows easily to add a bottom sheet and has collapse/expand and swipe features out of the box.</p><p>Feel free to follow me on Twitter, also don’t hesitate to ask questions related to this.</p><p>Twitter : <a href="https://twitter.com/a_rasul98">https://twitter.com/a_rasul98</a></p><p>Thanks for reading, and see you later!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8ab7a297aac" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/bottom-sheet-in-jetpack-compose-c8ab7a297aac">Bottom Sheet in Jetpack Compose</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[ShapeableView in Jetpack Compose. Part 2]]></title>
            <link>https://proandroiddev.com/shapeableview-in-jetpack-compose-part-2-f52cf6fb1509?source=rss-d6e17d68032d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f52cf6fb1509</guid>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Rasul Aghakishiyev]]></dc:creator>
            <pubDate>Tue, 16 Feb 2021 17:48:15 GMT</pubDate>
            <atom:updated>2021-02-18T16:21:25.456Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6NscSLS1t-5HNREQ.png" /></figure><p>In the <a href="https://proandroiddev.com/shapeableview-in-jetpack-compose-part-1-8b1b312b2fa4">post before</a> we learned how to create Shapes with cut corners. Today we will continue and add some new functionality such as rounded corners to our ShapeableView.</p><p>In previous examples, we had two corner types which were <strong>CUT and NONE.</strong> Let’s add <strong>ROUNDED</strong> corner type to our enum class.</p><pre>enum class CornerType {<br>    <em>CUT</em>,<br>    <em>ROUNDED</em>,<br>    <em>NONE<br></em>}</pre><p>Also, we add when expression to control which corner type selected for every corner:</p><pre>when (decoration.topStart.type) {<br>    CornerType.<em>CUT</em>, CornerType.<em>NONE </em>-&gt; {<br>        moveTo(0f, topStartSize)<br>        lineTo(topStartSize, 0f)<br>    }<br>    CornerType.<em>ROUNDED_IN </em>-&gt; {<br>        // There will be our code<br>    }<br>}</pre><p>We will use <strong>arcTo </strong>to draw round corners.</p><pre>fun arcTo(<br>    rect: Rect,<br>    startAngleDegrees: Float,<br>    sweepAngleDegrees: Float,<br>    forceMoveTo: Boolean<br>)</pre><p>It takes 4 arguments. Let’s look at each of them</p><p>rect — The bounds of oval defining shape and size of the arc This value cannot be null.</p><p>startAngleDegrees — Starting angle (in degrees) where the arc begins.</p><p>sweepAngle — Sweep angle (in degrees) measured clockwise, treated mod 360.</p><p>forceMoveTo—if the argument is true, starts a new subpath consisting of an arc segment.</p><p>So basically we draw the rect in our shape in with given offset and size.</p><p>Before we start draw our arc, you should know how to degrees placed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*d3wtP4-sXE9Nr4yJmsUkaw.png" /></figure><p>As you can see 0 degree is in the right center, not in the top center. And it move clockwise.</p><p>Now let draw our first round corner. We will start from topStart corner. First we need create Rect where our circle will be placed.</p><p>Our rect must placed at top start corner with size equal to our top start corner size:</p><pre>arcTo(<br>    rect = <em>Rect</em>(<br>        <em>Offset</em>(0f, 0f),<br>        <em>Size</em>(topStartSize, topStartSize)<br>    ),<br>    startAngleDegrees = 180f,<br>    sweepAngleDegrees = 90f,<br>    forceMoveTo = false<br>)<br></pre><p><strong>Rect</strong> constructor takes two parameters:</p><pre>offset: Offset<br>size: Size</pre><p>offset — The <strong>top left</strong> corner of the rect</p><p>size — The size of the rect</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*3UCLYvyasXDXn4RvXQd7-A.png" /><figcaption>The way how our arc will be draw</figcaption></figure><p>So our arc starts at 180 degree and move 90 degrees clockwise.</p><p>And the result will be like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*MSdiqj8j9-Juo6H6FgIe8w.png" /></figure><p>I will not dive deeply into other corners creation, just place the code for every corner below</p><p><strong>TOP_END</strong></p><p>Our rect must placed at top end corner with size equal to our top end corner size:</p><pre>arcTo(<br>    rect = <em>Rect</em>(<br>        <em>Offset</em>(x = size.width - topEndSize, y = 0f),<br>        <em>Size</em>(width = topEndSize,height = topEndSize)<br>    ),<br>    startAngleDegrees = 270f,<br>    sweepAngleDegrees = 90f,<br>    forceMoveTo = false<br>)</pre><p><strong>BOTTOM_END</strong></p><p>Our rect must placed at bottom end corner with size equal to our bottom end corner size:</p><pre>arcTo(<br>    <em>Rect</em>(<br>        <em>Offset</em>(x = size.width - bottomEndSize, y = size.height - bottomEndSize),<br>        <em>Size</em>(width = bottomEndSize,height = bottomEndSize)<br>    ),<br>    0f,<br>    90f,<br>    forceMoveTo = false<br>)</pre><p><strong>BOTTOM_START</strong></p><p>Our rect must placed at bottom start corner with size equal to our bottom start corner size:</p><pre>arcTo(<br>    rect = <em>Rect</em>(<br>        <em>Offset</em>(x = 0f, y = size.height - bottomStartSize),<br>        <em>Size</em>(width = bottomStartSize,height = bottomStartSize)<br>    ),<br>    startAngleDegrees = 90f,<br>    sweepAngleDegrees = 90f,<br>    forceMoveTo = false<br>)</pre><p>Now it’s time to combine cut and rounded corner types and see result</p><p>For example:</p><pre>@Composable<br>fun ShapeableView() {<br>    <em>Box</em>(<br>        modifier = Modifier<br>            .<em>size</em>(150.<em>dp</em>)<br>            .<em>clip</em>(<br>                Shapeable(<br>                    decoration = ShapeDecoration(<br>                        topStart = ShapeCorner(<br>                            type = CornerType.<em>CUT</em>,<br>                            size = 25.<em>dp<br>                        </em>),<br>                        topEnd = ShapeCorner(<br>                            type = CornerType.<em>ROUNDED_IN</em>,<br>                            size = 75.<em>dp<br>                        </em>),<br>                        bottomEnd = ShapeCorner(<br>                            type = CornerType.<em>CUT</em>,<br>                            size = 25.<em>dp<br>                        </em>),<br>                        bottomStart = ShapeCorner(<br>                            type = CornerType.<em>ROUNDED_IN</em>,<br>                            size = 75.<em>dp<br>                        </em>),<br>                    ),<br>                )<br>            )<br>            .<em>background</em>(Color.Gray)<br>    )<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*cKMWdul8r83jKj0yR8vNyw.png" /></figure><p>Since we created a shape, it means we can apply this corners to any shape.</p><p>For example Image:</p><pre>@Composable<br>fun ShapeableImage() {<br>    <em>Image</em>(<br>        <em>imageResource</em>(id = R.drawable.<em>android2</em>), contentScale = ContentScale.Crop,<br>        modifier = Modifier<br>            .<em>size</em>(150.<em>dp</em>)<br>            .<em>clip</em>(<br>                Shapeable(<br>                    decoration = ShapeDecoration(<br>                        topStart = ShapeCorner(<br>                            type = CornerType.<em>CUT</em>,<br>                            size = 55.<em>dp<br>                        </em>),<br>                        bottomEnd = ShapeCorner(<br>                            type = CornerType.<em>ROUNDED_IN</em>,<br>                            size = 55.<em>dp<br>                        </em>),<br>                    ),<br>                )<br>            )<br>    )<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*86q6FcQzPKsPJim9O0mM8w.png" /></figure><h3>Conclusion</h3><p>Today we created a shape that the same functionality as ShapeableImageView from Material Components which gives you the ability to modify every corner of the view. The main difference between them is that you can clip any composable view with this shape,</p><p>I hope it will help to make your life easier and the development process more enjoyable</p><p>Feel free to follow me on <a href="https://twitter.com/a_rasul98">Twitter</a>. Also, don’t hesitate to ask questions</p><p>Thanks for reading, and see you later!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f52cf6fb1509" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/shapeableview-in-jetpack-compose-part-2-f52cf6fb1509">ShapeableView in Jetpack Compose. Part 2</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[Compose for Desktop]]></title>
            <link>https://proandroiddev.com/compose-for-desktop-1cb05dff8710?source=rss-d6e17d68032d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cb05dff8710</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[jetbrains]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Rasul Aghakishiyev]]></dc:creator>
            <pubDate>Fri, 12 Feb 2021 17:34:40 GMT</pubDate>
            <atom:updated>2021-02-16T14:54:50.948Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ggh00YrLU8HVYP25Quo8jQ.png" /></figure><p>Declarative way programming becomes so popular nowadays. There are a lot of frameworks such as Flutter, SwiftUI, JetPack Compose which use this way of programming. Until recently Flutter and SwiftUI were the only frameworks that allow you to develop cross-platform applications using the same codebase. But today, meet new framework <strong>Compose for Desktop.</strong></p><p>Compose for Desktop is a UI framework port for developing applications for macOS, Linux, Windows. It uses the core Compose repository developed by Google. It is currently in the alpha version, but despite that, we will try to create a simple app using it.</p><h3>Usage</h3><p>For developing applications using Compose for Desktop, you need to install the latest version of Intellij Idea (The community version also supports it). The main requirement is <strong>JDK 11</strong></p><p>To create a new project:</p><p>File -&gt; New Project -&gt;Kotlin -&gt; Desktop uses Kotlin 1.4.20</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WYszZrcogMhDdiLctRs9GQ.png" /></figure><p>Then select the template: <strong>Compose Desktop Application </strong>and click <strong>Finish.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLt6FMoOrjAsvV4A77ZxhQ.png" /></figure><p>Our project structure will looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*HOrKgr2y-rqr9Dmt6GmXOA.png" /></figure><p>You can see there’s only one file in <strong>the src</strong> folder called <strong>main.kt. </strong>Let’s open it and see what is inside of it</p><pre>fun main() = <em>Window </em><strong>{<br>    </strong>var text by <em>remember </em><strong>{ </strong><em>mutableStateOf</em>(&quot;Hello, World!&quot;) <strong>}<br><br>    </strong><em>MaterialTheme </em><strong>{<br>        </strong><em>Button</em>(onClick = <strong>{<br>            </strong>text = &quot;Hello, Desktop!&quot;<br>        <strong>}</strong>) <strong>{<br>            </strong><em>Text</em>(text)<br>        <strong>}<br>    }<br>}</strong></pre><p>There is just one function called <strong>main</strong>. As you know the main function is the starting point of any Java applications</p><p>Let’s look closely at this function. It returns <strong>the Window</strong> composable.</p><p><strong>Window</strong> — function which opens a window with the given content.</p><p>If we go to the source code we can see that this function has a lot of other parameters that can be used</p><pre>title: String = &quot;JetpackDesktopWindow&quot;,<br>size: IntSize = <em>IntSize</em>(800, 600),<br>location: IntOffset = IntOffset.Zero,<br>centered: Boolean = true,<br>icon: BufferedImage? = null,<br>menuBar: MenuBar? = null,<br>undecorated: Boolean = false,<br>events: WindowEvents = WindowEvents(),<br>onDismissRequest: (() -&gt; Unit)? = null,<br>content: @Composable () -&gt; Unit = <em>emptyContent</em>()</pre><p>But for now, we will not change these parameters.</p><p><strong>MaterialTheme</strong> — Styles your application from the Material design specification. If you are an Android Developer you would be familiar with this.</p><p>There are also other things like <strong><em>remember</em></strong><em>, </em><strong><em>mutableStateOf. </em></strong>Don’t think about them for now<strong><em>, </em></strong>we will cover them in our next lesson.</p><p>Now if we run our application we will see this output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EAQihzQs18ggYHtK0-ozJw.png" /></figure><p>Let’s change our UI a little bit. For example center horizontally our button. For doing this we will use <strong>Column</strong> composable.</p><p>After some changes our code looks like this:</p><pre><em>Column</em>(horizontalAlignment = Alignment.CenterHorizontally) <strong>{<br>    </strong><em>Button</em>(onClick = <strong>{<br>        </strong>text = &quot;Hello, Desktop!&quot;<br>    <strong>}</strong>) <strong>{<br>        </strong><em>Text</em>(text)<br>    <strong>}<br>}</strong></pre><p>So let’s run our application to see the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EAQihzQs18ggYHtK0-ozJw.png" /></figure><p>Oh, nothing changed :( But wait let me explain something.</p><p>Column composable by default wraps the content and gets the same size as its content. So to make our button horizontally centered, we should resize our Column width to make it fill our application windows width. For this purpose, there is <strong>a Modifier</strong> parameter that has <strong><em>fillMaxWidth </em></strong>function.</p><p>And now our code will be like this:</p><pre><em>MaterialTheme </em><strong>{<br>    </strong><em>Column</em>(<br>        horizontalAlignment = Alignment.CenterHorizontally, <br>        modifier = Modifier.<em>fillMaxWidth</em>()) <strong>{<br>        </strong><em>Button</em>(onClick = <strong>{<br>            </strong>text = &quot;Hello, Desktop!&quot;<br>        <strong>}</strong>) <strong>{<br>            </strong><em>Text</em>(text)<br>        <strong>}<br>    }<br>}</strong></pre><p>And if run our application again, we will see that everything work as we wanted:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ttEMpTJdyl6vDie3GaG9EA.png" /></figure><p>Looks cool right?</p><h3>Conclusion</h3><p>Compose for Desktop is a very new but perspective framework, that will helps developers to create applications quickly with minimum code changes using the same codebase. And this will allow you to have the same UI and behavior across the platforms.</p><p>Feel free to follow me on <a href="https://twitter.com/a_rasul98">Twitter</a>, also don’t hesitate to ask questions related to this.</p><p>Thanks for reading, and see you later!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cb05dff8710" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/compose-for-desktop-1cb05dff8710">Compose for Desktop</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[ShapeableView in Jetpack Compose. Part 1]]></title>
            <link>https://proandroiddev.com/shapeableview-in-jetpack-compose-part-1-8b1b312b2fa4?source=rss-d6e17d68032d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b1b312b2fa4</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Rasul Aghakishiyev]]></dc:creator>
            <pubDate>Sat, 06 Feb 2021 19:25:17 GMT</pubDate>
            <atom:updated>2021-02-08T06:22:36.779Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1mXCWeeG5pBdbhEh8ruD0w.png" /></figure><p>In the previous <a href="https://agarasul.medium.com/shapes-in-jetpack-compose-de740f5507f2">story</a>, I talked about how to create a different types of shapes in Jetpack Compose.</p><p>In Material Components we have a widget called <strong>ShapeableImageView. </strong>Today we will create the Composable View that allows having a different type of corners</p><p>In Material Components we have a widget called <strong>ShapeableImageView</strong>. It allows you to change the shape of your image to circle, diamond, and so on. And also, using this widget you can set a corner radius to your ImageView. Today we will create the Composable View that allows having a different type of corners</p><p>First, we need to composable function:</p><pre>@Composable<br>fun ShapeableView() {<br>    <em>Box</em>(<br>        modifier = Modifier<br>            .<em>size</em>(150.<em>dp</em>)<br>    )<strong><br></strong>}</pre><p>It’s a simple composable view without any logic.</p><p>Corners will be three types: rounded, cut, and none if our view corner is a straight line</p><p>For this create enum class called <strong>CornerType</strong></p><pre>enum class CornerType {<br>    <em>CUT</em>,<br>    <em>ROUNDED</em>,<br>    <em>NONE<br></em>}</pre><p>In this lesson, we will just use <strong>the CUT</strong> corner type, but in the next lesson, we will add other corner types.</p><p>Also, we need a class that keeps the information about corner type and size. By default, our shapes don’t have corners.</p><pre>data class ShapeCorner(<br>    val type: CornerType = CornerType.<em>NONE</em>,<br>    val size: Dp = 0.<em>dp<br></em>)</pre><p>In case every corner of our shape can be modified, we should have a data class that will hold information about every corner</p><pre>data class ShapeDecoration(<br>    val topStart: ShapeCorner = ShapeCorner(),<br>    val topEnd: ShapeCorner = ShapeCorner(),<br>    val bottomEnd: ShapeCorner = ShapeCorner(),<br>    val bottomStart: ShapeCorner = ShapeCorner()<br>)</pre><p>So the initial setup is done. Now we will write our shape render logic</p><ol><li>Create a class that extends Shape interface with <strong>shapeDecoration</strong> parameter in its constructor</li></ol><pre>class Shapeable(private val decoration: ShapeDecoration) : Shape {<br>    override fun createOutline(size: Size, density: Density): Outline {<br>        <em>/**<br>         * There will be our code<br>         */<br>    </em>}<br>}</pre><p>We will use Path for creating custom shapes. To do this we must get the size of every corner in pixels because all calculations below will be in pixels.</p><p>To convert <strong>Dp</strong> into pixels we just multiply our value by the current <strong>density</strong></p><pre>val topStartSize = decoration.topStart.size.value * density.density<br>val topEndSize = decoration.topEnd.size.value * density.density<br>val bottomEndSize = decoration.bottomEnd.size.value * density.density<br>val bottomStartSize = decoration.bottomStart.size.value * density.density</pre><p>Next we will write logic for <strong>CUT</strong> corner type:</p><p>Our drawing path will be like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TiM5VbrQ9h5jyZX1KtQ91A.png" /></figure><p>So to make cut corner, we should cut our shape sides. For example, for the top cut corner, we must cut <strong>topStartSize </strong>from our top and left sides. The code below shows how to do this.</p><p>Our first point has coordinates x= 0f and y = topStartSize. To cut left corner we line to position x= topStartSize and y = 0f.</p><pre>moveTo(0f, topStartSize)<br>lineTo(topStartSize, 0f)</pre><p>Then we will cut our bottom right corner :</p><pre>lineTo(size.width - topEndSize, 0f)<br>lineTo(size.width, topEndSize)</pre><p>And finally our bottom left corner:</p><pre>lineTo(size.width, size.height - bottomEndSize)<br>lineTo(size.width - bottomEndSize, size.height)</pre><p>That’s it. We just created a shape that will cut our corner as we want. Let’s try it.</p><pre>@Preview<br>@Composable<br>fun ShapeableViewTest() {<br>    <em>Box</em>(<br>        modifier = Modifier<br>            .<em>size</em>(150.<em>dp</em>)<br>            .<em>clip</em>(<br>                Shapeable(<br>                    decoration = ShapeDecoration(<br>                        topStart = ShapeCorner(<br>                            type = CornerType.<em>CUT</em>,<br>                            size = 50.<em>dp<br>                        </em>),<br>                    ),<br>                )<br>            )<br>            .<em>background</em>(Color.Gray)<br>    ) <strong>{<br>    }<br></strong>}</pre><p>The output will be something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*t2KyuStu71-ryBuP4EJjZA.png" /></figure><p>Also we can cut two corners of our shape:</p><pre>@Preview<br>@Composable<br>fun ShapeableViewTest() {<br>    <em>Box</em>(<br>        modifier = Modifier<br>            .<em>size</em>(150.<em>dp</em>)<br>            .<em>clip</em>(<br>                Shapeable(<br>                    decoration = ShapeDecoration(<br>                        topStart = ShapeCorner(<br>                            type = CornerType.<em>CUT</em>,<br>                            size = 50.<em>dp<br>                        </em>),<br>                        <strong>bottomEnd = ShapeCorner(<br>                            type = CornerType.<em>CUT</em>,<br>                            size = 50.<em>dp<br>                        </em>),</strong><br>                    ),<br>                )<br>            )<br>            .<em>background</em>(Color.Gray)<br>    ) <br>}</pre><p>And the output now will be like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*P-WKMLUBQVCaQb62YUcBeQ.png" /></figure><p>Or we can make a diamond shape:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*HHUenAGQWwGkxurGSIbX0Q.png" /></figure><pre>@Preview<br>@Composable<br>fun ShapeableViewTest() {<br>    <em>Box</em>(<br>        modifier = Modifier<br>            .<em>size</em>(150.<em>dp</em>)<br>            .<em>clip</em>(<br>                Shapeable(<br>                    decoration = ShapeDecoration(<br>                        topStart = ShapeCorner(<br>                            type = CornerType.<em>CUT</em>,<br>                            size = 75.<em>dp<br>                        </em>),<br>                        topEnd = ShapeCorner(<br>                            type = CornerType.<em>CUT</em>,<br>                            size = 75.<em>dp<br>                        </em>),<br>                        bottomStart = ShapeCorner(<br>                            type = CornerType.<em>CUT</em>,<br>                            size = 75.<em>dp<br>                        </em>),<br>                        bottomEnd = ShapeCorner(<br>                            type = CornerType.<em>CUT</em>,<br>                            size = 75.<em>dp<br>                        </em>),<br>                    ),<br>                )<br>            )<br>            .<em>background</em>(Color.Gray)<br>    )<br>}</pre><h3>Conclusion</h3><p>Today we created a Shapeable component that allows you to cut every corner. I hope it will help you to create an awesome UI and make your development easier.</p><p>Feel free to follow me on <a href="https://twitter.com/a_rasul98">Twitter</a>. Also, don’t hesitate to ask questions</p><p>Thanks for reading, and see you later!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b1b312b2fa4" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/shapeableview-in-jetpack-compose-part-1-8b1b312b2fa4">ShapeableView in Jetpack Compose. Part 1</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>
    </channel>
</rss>