<?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 Akshay Rana GuJJar on Medium]]></title>
        <description><![CDATA[Stories by Akshay Rana GuJJar on Medium]]></description>
        <link>https://medium.com/@akshayranagujjar?source=rss-460a6b1804bb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*FrENL7ev1hDrQ0xe.</url>
            <title>Stories by Akshay Rana GuJJar on Medium</title>
            <link>https://medium.com/@akshayranagujjar?source=rss-460a6b1804bb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 23:40:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akshayranagujjar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Android Event Bus with Example]]></title>
            <link>https://akshayranagujjar.medium.com/android-event-bus-with-example-ec6b9f6522e2?source=rss-460a6b1804bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec6b9f6522e2</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-tutorials]]></category>
            <category><![CDATA[eventbus]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Akshay Rana GuJJar]]></dc:creator>
            <pubDate>Thu, 10 Sep 2020 13:37:00 GMT</pubDate>
            <atom:updated>2020-09-11T18:46:55.740Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Android Event Bus with Example" src="https://cdn-images-1.medium.com/max/1024/1*jsU-FpeeWR20Z8TA0JBjVA.jpeg" /></figure><p><strong>EventBus</strong> is the number 1 event library for android and java. <strong>EventBus</strong> uses the publisher and subscriber pattern for loose coupling which means the possibility of errors will be less. <strong>EventBus</strong> simplifies the communication between different components for example communications between different levels of activities or even services. You need very less or no setup to use <strong>EventBus</strong> in your existing project.</p><p><strong>EventBus</strong> provides a convenient annotation-based API which makes it fast and the performance is increased. EventBus is used by many popular apps, apps which has 1 billion-plus download which shows how EventBus popular.</p><p>In this tutorial, we will see how we can get started using EventBus in an android project. Before jumping in the code let’s see what we will be going to make. To better understanding EventBus we will make an app that allows us to add items to the cart and show the total count of the items. See below how our app will work.</p><figure><img alt="EventBus App example" src="https://cdn-images-1.medium.com/max/491/1*0QI0ofUzO2EQmOWdW3-vjA.gif" /></figure><p>Let’s get started.</p><h3>Add EventBus Dependency in Android Studio</h3><p>First, we need to add EventBus Dependency in the project. Open your build.gradle and add the dependency.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cee4fa3802dc25fd2b8ce74d17ca53c0/href">https://medium.com/media/cee4fa3802dc25fd2b8ce74d17ca53c0/href</a></iframe><p>Hit the sync button and move to the next step.</p><h3>Make a POJO class for EventBus</h3><p>The next step is to make a Java object class to pass in the EevntBus Subscribe method and to be used later.</p><p>For our example app, we will make a class with the name of CartEvent.java with a string field for cart items.</p><p>See the below code for better understanding.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/597083f39962e7f1bf9c9ff72e85a9fb/href">https://medium.com/media/597083f39962e7f1bf9c9ff72e85a9fb/href</a></iframe><p>Move to the next step.</p><p>See also: <a href="https://www.akshayrana.in/2020/08/top-10-libraries-for-android-developers.html"><strong>Should Know Libraries for Android Developers</strong></a></p><h3>Make UI for the App</h3><p>In the first activity, we have a textview to show the total count of the cart item.</p><p>And a button to open second activity to add items in the cart.</p><p>See the below code to understand.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/477575b21bdbe029075b2d8090e0a6ee/href">https://medium.com/media/477575b21bdbe029075b2d8090e0a6ee/href</a></iframe><p>Now make the second activity to show the items list and add a method for the button click.</p><p>We made simple cart items. We add 3 items but in the real world application, you should use <a href="https://www.akshayrana.in/2020/06/what-is-recyclerview-in-android.html">recyclerview</a> or any other view to make a list of items.</p><p>Here is the second activity XML code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/147c8f74a30beb9946e9e5068ea73d9e/href">https://medium.com/media/147c8f74a30beb9946e9e5068ea73d9e/href</a></iframe><p>In the above code, we have added the onClick attribute and pass the addItemToCart method name.</p><p>And made the appropriate method in the second activity java.</p><p>Now implement EventBus in the project.</p><p>Let’s make the subscriber and in the subscriber method, we will add items to the list.</p><p>See below to understand.</p><h3>Make Subscribe Method of EventBus to update Cart</h3><p><em>Read Further Article at </em><a href="https://www.akshayrana.in/2020/09/event-bus-in-android-with-example.html">https://www.akshayrana.in/2020/09/event-bus-in-android-with-example.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec6b9f6522e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Firebase Cloud FireStore Database in Android]]></title>
            <link>https://akshayranagujjar.medium.com/how-to-use-firebase-cloud-firestore-database-in-android-b4006a3c24f8?source=rss-460a6b1804bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4006a3c24f8</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[firestore]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[androiddevweekly]]></category>
            <category><![CDATA[android-java]]></category>
            <dc:creator><![CDATA[Akshay Rana GuJJar]]></dc:creator>
            <pubDate>Tue, 08 Sep 2020 18:06:46 GMT</pubDate>
            <atom:updated>2020-09-08T18:22:29.466Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello World, today we are going to see how we can make a todo app using a <strong>firebase cloud firestore database</strong>. The <strong>Firestore database </strong>is a very flexible and scalable NoSQL database to make our development very fast. <strong>Firestore</strong> is very easy to use in android.</p><p>FireStore can work smoothly even of your device is offline it can fetch data from the cache in the device so that your app can work offline and update the data when it connects to the internet again. This functionally makes your app for interactive for the users. <strong>Firestore database</strong> has one more feature is to watch realtime changes in the database and you can show updates in the app.</p><p>Firestore database can execute queries so that you can filter your data as per your requirement, this feature makes the firestore database more likely to choose for your project.</p><p>Firestore database stores the data in the documents and these documents are saved in the collection. Think it like the collection is a file folder that has multiple documents and these documents have some data written on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*1rxhN02dw7sFvGEA.jpg" /><figcaption>Firestore collection and document</figcaption></figure><p>Let’s check our app which will be going to build using Firebase Cloud FireStore Database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/0*fdprNlpPbP-JIkob.gif" /></figure><p>Let’s make our app.</p><h3>Make a new project in Firebase Console</h3><p>The first thing we need to make a new project in the firebase console. Let’s head to <a href="https://console.firebase.google.com/">https://console.firebase.google.com/</a> and make a new project by clicking on the new project. Follow all the instructions.</p><figure><img alt="Create new project in firebase" src="https://cdn-images-1.medium.com/max/976/1*UWXCiWfGOnu7eoUjrXGyhQ.png" /></figure><p>After creating the project lets add our android project. Click on the android icon.</p><figure><img alt="To do app project in firebase" src="https://cdn-images-1.medium.com/max/542/1*fEJK0_9F7ki5enMuE0qOZw.png" /></figure><p>and then fill your package name then app name.</p><p>Download the google-services.json file and paste this file in the app folder of your app.</p><p>After that follow the instructions of the firebase. Add required dependencies and hit the sync button.</p><p>Your dependencies will look like below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4b1257b9c1d67f34ac258353307433f/href">https://medium.com/media/d4b1257b9c1d67f34ac258353307433f/href</a></iframe><p>We have added dependencies for firestore and <a href="https://www.akshayrana.in/2020/06/what-is-recyclerview-in-android.html">recyclerview</a>.</p><p>Now let’s move to make layout our app.</p><h3>Make Layout of the Application</h3><p>To make the layout we will add this code in our activity_main.xml file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62d56d5d39e44baf092f5f5786915de2/href">https://medium.com/media/62d56d5d39e44baf092f5f5786915de2/href</a></iframe><p>In the above code, we have added an edit text, a button, and a <a href="https://www.akshayrana.in/2020/06/what-is-recyclerview-in-android.html">recyclerview</a>.</p><p>add below dependency in your app level build.gradle file to use <a href="https://www.akshayrana.in/2020/06/what-is-recyclerview-in-android.html">recyclerview</a> in the project.</p><pre>implementation &#39;androidx.recyclerview:recyclerview:1.1.0&#39;</pre><p>If you want to know more about <a href="https://www.akshayrana.in/2020/06/what-is-recyclerview-in-android.html">recyclerview</a> you can check it here.</p><p>Now we need to make the item layout of the <a href="https://www.akshayrana.in/2020/06/what-is-recyclerview-in-android.html">recyclerview</a>.</p><p>Make a new layout file and add this code to it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7088324f72ace622cf795159591af29/href">https://medium.com/media/e7088324f72ace622cf795159591af29/href</a></iframe><p>In the above code, we have a checkbox and an imageview to act as a delete button and set their respective ids.</p><p>If you want to add a delete icon in your project you can easily add this by right-clicking on drawable folded then select new and then click on the vector assets and in the next window choose your icon and icon name then save the icon and now you can use this icon in imageview.</p><p>After all this, we will add the functionality of our app.</p><p>Before making the functionality we need to create a database in the firebase console. Go to your firebase project and click on develop and choose the database and then click on create database.</p><p>Note that there will be 2 options. One for Cloud FireStore and in the below on that second option is for the realtime database. But we need to create a database for Cloud FireStore.</p><p>Now we need to make a model class (POJO object class) which will be using in the firebase and in the <a href="https://www.akshayrana.in/2020/06/what-is-recyclerview-in-android.html">recyclerview</a>.</p><h3>Make Model Class for Firebase and RecyclerView</h3><p>We need to make a model class that will hold the data. The model class will help to set the data and get the data using getter and setter functions. We have to specify the data type and number of fields that we want to use. See the below code to make a model for the to-do app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c42f8bdeead6b4d52ed49d9cc0350a1e/href">https://medium.com/media/c42f8bdeead6b4d52ed49d9cc0350a1e/href</a></iframe><p>In the above model class if you noticed we are using an annotation @DocumentId above the taskId. This annotation is telling that taskId field will be using as document id of the firebase document and when we add data to the firestore database this property will ignore to create in the firestore database. If you are not understanding what I am saying then keep reading you will understand.</p><p>Then we make a task string field for holding the task value as a string and the lat field is for either task is done or not. After that, we made the getters and setters method to set the values and get the values.</p><p>After making the model we will move to MainActivity.java and make adding data to database functionality.</p><h3>Add data to Firebase Firestore Using Model Class</h3><p>To add the task data in the firestore we need to get task value from edit text and on the click of the button, we will check the value if it is not empty and then we will use firebase functions to add the data, let’s see how.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d5e7fa690ba8fda94cdb79dd5d38016/href">https://medium.com/media/1d5e7fa690ba8fda94cdb79dd5d38016/href</a></iframe><p>In the above code, first, we create a database instance of firestore, and then we are getting our EditText and Button from the activity xml layout in the onCreate method.</p><p>Then we implement click listener on the button and this will add data in the firestore database. In the click method first, we are getting a string from the edit text and then check if the string is not empty. If the string is empty then we show a toast and then return from the method.</p><p>Then we create our task model object and set values using setter methods. We set taskDone to false and set task string. Notice that we are not setting the taskId as it will handle by the Firebase library.</p><p>Now, this the point where we will add the data to the database.</p><p>First, we get the reference of the collection by using the db.collection method and then call the add method and pass our model which we just created above and then we add the success listener.</p><p>In the success listener, we remove the string from the EditText.</p><p>Now if you run your app then enter a task in the EditText and click on the add button. Check your database in the Firebase console there will be the newly created document in your collection.</p><p>Note that collection is created automatically if it does not exist.</p><p>This is how we add the data in the <strong>Firestore Database</strong>.</p><p>Now see how we can get the data from the database and show in the <a href="https://www.akshayrana.in/2020/06/what-is-recyclerview-in-android.html">recyclerview</a>.</p><h3>Fetch Data from FireStore Database &amp; show in RecyclerView</h3><p>For showing the data in the <a href="https://www.akshayrana.in/2020/06/what-is-recyclerview-in-android.html">recyclerview</a> we need to make an adapter class for the recyclerview as we do while implement recyclerview. So let’s make a new java file and extend it to a recyclerview adapter.</p><p>Then we need to pass our viewholder class to do that we create an inner class in our adapter class and pass this class as generic in the adapter and implement the all required methods.</p><p>After creating all the classes we need to make a constructor with parameters. These parameters are Context, List of a task model, and db reference.</p><p>See the below code for better understanding.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1e4adab57c5976d824143473c4019a0/href">https://medium.com/media/a1e4adab57c5976d824143473c4019a0/href</a></iframe><p>Return the list size in the getItemCount method. Now come to the viewholder class and write the below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b99c153ac56d446b3dd1f91dfd4d514/href">https://medium.com/media/0b99c153ac56d446b3dd1f91dfd4d514/href</a></iframe><p>If you remember we have created task_item.xml with a checkbox and an imageview for the delete button. We will use these elements in the viewholder and create their references to work with them.</p><p>And in the onBindViewHolder method in the adapter. We are setting the checkbox text and its check state.</p><p>Now the main thing is to update the existing task value in the database. We want to update the task done value in the database when user check or uncheck the checkbox. We have to add a listener to this in the viewholder.</p><p>Inflate our task_item.xml view in onCreateViewHolder.</p><p>See also: <a href="https://www.akshayrana.in/2020/07/how-to-make-dark-night-mode-theme-in.html"><strong>How to make Night Theme In Android App</strong></a></p><h3>Update Value in FiresStore Database</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5b68212b0e2b00fa82103bb188a0a61/href">https://medium.com/media/e5b68212b0e2b00fa82103bb188a0a61/href</a></iframe><p>First, we get the current item position and then the item’s task id to update the document in the database.</p><p>Again we get the reference to the collection then get the document reference by passing the task id in the document method this id is the document id. If you open you collection in the firebase console then the random string are shown are the document ids.</p><p>We are using these ids as taskId.</p><p>After getting the reference to the document then we are calling the update function and in the first parameter, we pass the field name which we are going to update and the value to be set in the database.</p><p>If you run your app and click on the checkbox then the value in the firestore database will update.</p><p>Now if the user wants to delete the task so let’s make the delete functionality.</p><h3>Delete Document from FireStore Database</h3><p>To delete the document from the database. As we did above to update the value we call update method but for deleting the document, we will call the delete method on document reference and add a success listener to remove the task model from the list of task models and update the recyclerview.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c30710b315888b38fae1c4c67c196035/href">https://medium.com/media/c30710b315888b38fae1c4c67c196035/href</a></iframe><p>After removing the task we need to notify the adapter to update the recyclerview. So we called to notifyDataSetChanged method.</p><p>now at this point, we have completed the adapter code now attach the adapter to the recyclerview. Go to your activity java file and make an adapter construct with required parameters and set layout manager to the recyclerview and set the adapter to the recyclerview.</p><p>Then we fetch all the tasks and convert them to the task model add them to the list of the task model and notify the adapter for change in the list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/829202fb2b7734d42f5eead0f6cefbf1/href">https://medium.com/media/829202fb2b7734d42f5eead0f6cefbf1/href</a></iframe><p>You can read the further article here: <a href="https://www.akshayrana.in/2020/08/firebase-firestore-database-android.html">Firestore Database in Android</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4006a3c24f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make Dark (Night) Mode Theme in Android]]></title>
            <link>https://akshayranagujjar.medium.com/how-to-make-dark-night-mode-theme-in-android-a1c1bf95a302?source=rss-460a6b1804bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1c1bf95a302</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[dark-mode]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[night-mode]]></category>
            <dc:creator><![CDATA[Akshay Rana GuJJar]]></dc:creator>
            <pubDate>Fri, 31 Jul 2020 20:37:01 GMT</pubDate>
            <atom:updated>2020-07-31T20:37:01.662Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Dark (Night) Mode Theme in Android" src="https://cdn-images-1.medium.com/max/640/0*pxCmrCgjscDd87z5.jpg" /></figure><p>Hello World, today we are going to see how we can <strong>implement a dark theme or night mode</strong> in our android application. This tutorial is going to be very simple and easy to understand. The dark theme is attractive to users and it is comfortable for low light conditions. Recently many apps adapt dark mode in their app and the output of the <strong>night mode</strong> is amazing as many users love <strong>dark mode</strong> for their app. An example of a dark theme is Whatsapp dark mode in android see the below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*vqBw34sEuQVz7uvIaUNfkQ.png" /></figure><p>Let’s look at how our app will look like, see the below gif for our end result app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/0*VI2ENLtwx9fbw43U.gif" /></figure><p>Let’s see how we can implement dark theme in our app.</p><h3>Make layout for dark theme</h3><p>First, we need to make our layout so that we can apply our dark theme to it.</p><p>If you see the above gif we used <a href="https://www.akshayrana.in/2020/06/what-is-cardview-in-android.html">cardview</a> to make our layout.</p><p>See the below code for layout.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bd553e78f4504484d09c9e51b455c66/href">https://medium.com/media/8bd553e78f4504484d09c9e51b455c66/href</a></iframe><p>Now we need to set theme colors in the layout, for example, we need to set the background color of activity and <a href="https://www.akshayrana.in/2020/06/what-is-cardview-in-android.html">cardview</a> and also we need to set textview color and icon colors. But setting all the colors we need some way to set colors dynamically.</p><p>We want to change the background color of activity to dark black color when we apply our dark theme in the application.</p><p>To make the dynamic values we will need to make attrs.xml file in the values folder.</p><h3>Make custom attribute values for layout.</h3><p>Create a new xml file in the values folder. Right-click on values folder and click on new then click values resource file and type attrs in the file name field.</p><p>Your values folder should look like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/175/0*PjrG5Yp1mklFEpDh.png" /></figure><p>In the attrs.xml we will declare our custom attribute values like below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7380d00c73e52845e30072663d91b88/href">https://medium.com/media/f7380d00c73e52845e30072663d91b88/href</a></iframe><p>In the above code, we have defined 7 values and their type which is color. Each of the values, we will use in our layout file.</p><p>But before using these values we need to assign or set these values in our currently applied theme and also we will make our dark theme and update these attribute values.</p><p>See also: <a href="https://www.akshayrana.in/2020/06/recyclerview-and-cardview-example-android.html"><strong>Cardview with Recyclerview Example</strong></a></p><h3>Make Dark theme in styles.xml and set attributes value.</h3><p>First, we will set attribute values for our default or light theme then we will update those attribute values in the Dark theme. Let’s do this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ff56b37b4fe89312ea8801799ef2b4d/href">https://medium.com/media/0ff56b37b4fe89312ea8801799ef2b4d/href</a></iframe><p>In the AppTheme we are setting our attribute value you are free to change as per your need. We are setting default colors. Then we made a new theme called DarkAppTheme and now this time we are setting all the custom attribute values to the dark theme matching colors.</p><p>We have set the app background color to black and other background colors to dark colors and set text and icon colors according to the dark theme.</p><p>Now the time to use these values in our layout. Open your activity XML file and check the background and textColor values as shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/618e7187088c9eea31869875c831d403/href">https://medium.com/media/618e7187088c9eea31869875c831d403/href</a></iframe><p>If you noticed background and text color values, see how we use the attribute values in the activity layout so that these take values from the currently applied theme and set we set DarkAppTheme the values of the Dark theme will update and hence our layout values will also update and our dark theme will be in use.</p><p>Let’s see our we can switch our theme from the java code.</p><h3>Set Theme to DarkAppTheme using Java</h3><p>Now we have completed our XML part now its time to make logic to change the dark theme in the app.</p><p>If you want to read further then you can continue read here: <a href="https://www.akshayrana.in/2020/07/how-to-make-dark-night-mode-theme-in.html">Apply dark mode in android studio</a></p><p>Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1c1bf95a302" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make Custom Switch in Android?]]></title>
            <link>https://akshayranagujjar.medium.com/how-to-make-custom-switch-in-android-1ddcf2c708f5?source=rss-460a6b1804bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ddcf2c708f5</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[custom-switch]]></category>
            <dc:creator><![CDATA[Akshay Rana GuJJar]]></dc:creator>
            <pubDate>Thu, 23 Jul 2020 16:59:18 GMT</pubDate>
            <atom:updated>2020-07-23T16:59:18.119Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Custom Switch in Android akshayrana.in" src="https://cdn-images-1.medium.com/max/560/0*BpWhfgmSHWoCJLZd.png" /></figure><p>Hello World, Today we are going to make a custom switch. Why? Because the default one looks so boring and ugly. Why we use a switch? As the name suggests, the switch is used to trigger the value either it is on, or it is off. Let’s see, how our custom switch will look at the end of the tutorial.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/224/0*pCOF2T_m2os1QMIZ.gif" /></figure><p>In the above gif, there are 3 switches. The First one is the default one and the second and third are our custom switches. To make these custom switches we need to follow certain steps are as follows:</p><h3>Step 1. Add Switch to Activity Layout</h3><p>First. we need to add the switch to our layout XML file. We will add SwitchCompat to the layout.</p><p>Look at the below code for better understanding.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a4073b10b013441ee5c7f9a6db11d24/href">https://medium.com/media/8a4073b10b013441ee5c7f9a6db11d24/href</a></iframe><p>In the above code, things to be noticed are app:track and android:thumb attributes.</p><p>The track is the horizontal container where our thumb or round shape view is placed and the thumb is, as I told you before, is the round shape where we will add an image on top of it.</p><h3>Step 2. Make Custom Track for Switch</h3><p>To make our custom track we need to make a drawable file and set the root element as a selector. So click on the drawable folder and make a new file and name it as track.</p><p>In our track.xml we write this code for making the custom track.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d57cbda81003b8d3e1a9b6c1113f082/href">https://medium.com/media/0d57cbda81003b8d3e1a9b6c1113f082/href</a></iframe><p>In the above code, we made two items in the selector where the first item represents the state when the <a href="https://developer.android.com/reference/android/widget/Switch">switch</a> is off or not checked and the second item represents the state when the switch is on or checked.</p><p>In the first item, we made a shape of a rectangle and fill white color with having corner radius with a grey color stroke or outline and in the second item the only difference is filled color will be our accent color and stroke will be removed but the corner radius will be the same.</p><p>Now let’s make our thumb part where we will add images on the thumb.</p><h3>Step 3. Make Custom Thumb with Image.</h3><p>To make custom thumb for the switch, create a drawable file in a drawable folder and name it as the thumb.</p><p>In our thumb.xml file, we will write the below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d738ccb2a7bf21b3675b52fda6f24a89/href">https://medium.com/media/d738ccb2a7bf21b3675b52fda6f24a89/href</a></iframe><p>as track.xml here we also have the root element as a selector and have the same item tags but this time we set drawable in the attribute. These drawable are our drawable file where we will add images. Let’s add our vector icons to use in thumb drawable.</p><h3>Add images for thumb</h3><p>Right-click on drawable then click on new then select vector assets and then choose your icon from clip art. for demo purpose we are selecting notification on and off icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/50/0*JD2dSoMBWtqkY1RZ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/50/0*oVRNXEicJt4BAvH_.png" /></figure><p>After adding the icons, we need to make drawable files for custom thumb off and one for the thumb on which will be add in thumb.xml as drawable.</p><p>Let’s make the first file in the drawable for thumb off and set an image to the thumb. Check the below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89fa77d8b09a39ebe77858ca4842d55d/href">https://medium.com/media/89fa77d8b09a39ebe77858ca4842d55d/href</a></iframe><p>If you noticed, we are using the layer-list as the root element and in the child, we have 2 items.</p><p>The first item is our oval (round) shape of the thumb with the size and background color and the second item is our image drawable with 12dp padding from the top, bottom, left, and right.</p><p>See also: <a href="https://www.akshayrana.in/2020/06/recyclerview-and-cardview-example-android.html"><strong>Cardview with Recyclerview Example</strong></a></p><p>So this was for when the switch is off our custom thumb will look like this now its turn for thumb true when the switch is on.</p><p>Create a new file with the name switch_thumb_true and the code will be like below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd6ce9a81d6ade7a44006581bb00e054/href">https://medium.com/media/cd6ce9a81d6ade7a44006581bb00e054/href</a></iframe><p>Like thumb false, this code is similar to it but the differences are we added the stroke to the round shape and of course change the image drawable.</p><p>Now we have made the all necessary files now its time to run our app and your custom switch is ready. Tada!!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*EBvnJvuHTUvWLB-q.jpg" /></figure><p>This switch is our middle one if you want to make track height small then you need to do some extra work.</p><h3>How to make track height smaller than the thumb.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/100/1*FKv812SoSwraMVcd2sG_OQ.jpeg" /></figure><p>Read further here: <a href="https://www.akshayrana.in/2020/07/custom-switch-in-android.html">How to make Custom Switch in Android</a></p><p>Thank you and if you like this article please clap and share with others ❤</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ddcf2c708f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Custom Toast With Example]]></title>
            <link>https://medium.com/swlh/android-custom-toast-with-example-44ce5fe6d6ec?source=rss-460a6b1804bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/44ce5fe6d6ec</guid>
            <category><![CDATA[toast]]></category>
            <category><![CDATA[custom-toast]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Akshay Rana GuJJar]]></dc:creator>
            <pubDate>Tue, 14 Jul 2020 17:07:25 GMT</pubDate>
            <atom:updated>2020-07-17T13:16:19.689Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Android Custom Toast" src="https://cdn-images-1.medium.com/max/560/0*aFszBVC3gRVBbs13.png" /></figure><p>Hello World, today we will be going to see how we can make custom toast and in this tutorial, we will see custom toast with an example. See below as an example.</p><figure><img alt="Android Custom Toast gif" src="https://cdn-images-1.medium.com/max/368/0*q3SWg_ULe81NNdh6.gif" /></figure><p>Before starting let’s see.</p><h3>What is Toast? When to use it?</h3><p>Toast is a view that contains text which notifies the user with some information.</p><p>We can use toast when we want to notify the user.</p><h3>Making Custom Toast with Example</h3><p>To make custom toast we need to follow certain steps as follows.</p><h3>Step 1. Create a Custom Layout for Toast</h3><p>the first step is to make a layout file for our toast.</p><p>To make a layout file, right-click on layout folder under res and select new -&gt; layout resource file.</p><p>we will name this file as custom_toast.xml and in this file, we will make our layout which will b shown in the <a href="https://developer.android.com/guide/topics/ui/notifiers/toasts">toast</a>. Check the below code for the layout file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1625b9c4e1ab5047dc1b45a139d28aa2/href">https://medium.com/media/1625b9c4e1ab5047dc1b45a139d28aa2/href</a></iframe><p>In the above code, we set the id to the parent view and we added an imageview and a textview.</p><p>We are keeping things simple so that you can understand better.</p><p>our layout looks like this below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/184/0*j6i7FVgUNZ_73gf7.png" /></figure><h3>Step 2. Set layout file to the Toast</h3><p>To trigger the toast we made a button in the activity layout and calling the makeToast function on click.</p><p>Let’s see the code in the makeToast function.</p><p>Hey if you want to read full article read here: <a href="https://www.akshayrana.in/2020/07/custom-toast-with-example-in-android.html">Android Custom Toast With Example</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44ce5fe6d6ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/android-custom-toast-with-example-44ce5fe6d6ec">Android Custom Toast With Example</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make Bottom Navigation bar in Android]]></title>
            <link>https://akshayranagujjar.medium.com/how-to-make-bottom-navigation-bar-in-android-c8d4aeb5274f?source=rss-460a6b1804bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8d4aeb5274f</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[bottomnavigationview]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[navigation-bar]]></category>
            <dc:creator><![CDATA[Akshay Rana GuJJar]]></dc:creator>
            <pubDate>Mon, 13 Jul 2020 21:33:00 GMT</pubDate>
            <atom:updated>2020-07-13T21:55:41.507Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*OnkPcTDTBFLzU2On.png" /></figure><p>Hello World, Today we are going to learn how we can make a nice <strong>bottom navigation bar in android</strong>. We will see how we can implement <strong>bottom navigation</strong> and how to work with fragments and many other things and trust me you will enjoy this tutorial. Before making our <strong>bottom navigation bar</strong> lets look at our final result. See the below gif.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/0*5CTwC0ZywIlgBWe2.gif" /></figure><p>This is a clean and <strong>material design based bottom navigation bar</strong>. So let’s see how to code this.</p><h3>Add Bottom Navigation Bar Dependency</h3><p>To make the bottom nav bar, first, we need to add the dependency for the bottom navigation bar.</p><p>Open your build.gradle file and add this dependency.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0097b45cdfb7056d1ff566e32a3412d5/href">https://medium.com/media/0097b45cdfb7056d1ff566e32a3412d5/href</a></iframe><p>After adding the dependency hit the sync button and after syncing the project, we can use BottomNaigationView in our layout file.</p><h3>Add BottomNavigationView in Layout</h3><p>Open your layout file and in the layout XML, we need to add 2 things. The first thing is FrameLayout, which will contain our fragments and the second thing is <a href="https://developer.android.com/reference/com/google/android/material/bottomnavigation/BottomNavigationView">BottomNavigationView</a>.</p><p>See the below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cef4beb8fcc8133f9d2d90528407a9a/href">https://medium.com/media/3cef4beb8fcc8133f9d2d90528407a9a/href</a></iframe><p>Explanation:</p><p>First, we have ConstraintLayout as parent layout and then in children we have, FrameLayout and BottomNavigationView.</p><p>Nothing is fancy here except BottomNavigationView. Have you noticed the app:menu=”@menu/bottom_nav_menu”. In this line, we have created a menu for our bottom nav which we will see later. Let’s move further.</p><p>Next, we have app:itemIconTint and ;app:itemTextColor which has the same value @color/bottom_nav_item_selector. So what this property means and what is the value. These properties or attributes help us to change the nav icon color.</p><p>If you noticed the bottom nav icon color they are white in color and the active screen has solid white color and rest are having off white color. How you can customize these bottom navigation bar icons? I will tell you later in this tutorial.</p><p>Next is app:labelVisibilityMode and the value is “labeled”. This property is responsible for weather showing text below of the icons in Bottom Navigation Bar. There are other values are as follows:</p><ul><li>Selected</li><li>Unlabeled</li><li>Auto</li></ul><p>Selected: Text will be shown only selected navigation item.</p><p>Unlabeled: Text will be hidden in navigation.</p><p>Auto: Icon text will be shown if there are 3 or less items in navigation and text will be shown only at the selected item when there are 4 or more items in navigation.</p><p>Now let’s see how to add items or menu in the bottom navigation.</p><h3>How to make menu for BottomNavigationView?</h3><p>To make menu for the bottom navigation bar, first, we need to make a menu folder under the res folder.</p><p>To make a folder under res, right-click on res folder in android studio and then click new then click on Android Resource Directory.</p><p>Then a popup window comes and click on resource type and select menu and hit OK.</p><p>Now your menu folder is created. Now we need to make our menu resource file. To do that we need to right-click on the menu folder and click on new -&gt; Menu Resource File.</p><p>Now we name our menu file same as in BottomNavigationView in activity layout file which is bottom_nav_menu.</p><p>See also: <a href="https://www.akshayrana.in/2020/02/gradient-status-bar-and-toolbar-android.html"><strong>Gradient Status bar and Toolbar</strong></a></p><p>In this file, we will add out menu item as shown below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f52809086d86504a8485b638828cae1/href">https://medium.com/media/7f52809086d86504a8485b638828cae1/href</a></iframe><p>In the above code, we made 4 items for our bottom navigation. Each item has an id, an icon, and title. Simple.</p><p>Now see how we can customize the icon color of items.</p><h3>How to Change Icon Color of BottomNavigationView?</h3><p>To change icon color when an item is selected in the bottom navigation bar like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/0*5Z_2Yc61yKNhrCrJ.jpg" /></figure><p>You will need to make your own color selector XML file. Follow the tutorial.</p><p>First, make color directory under the res folder. Right click on res folder and select new -&gt; Android Resource Directory.</p><p>Hey read the full article here: <a href="https://www.akshayrana.in/2020/07/bottom-navigation-bar-in-android.html">Bottom Navigation Bar in Android</a></p><p>Thank you for reading and have a nice day.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8d4aeb5274f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Skeleton content loading animation in android | Facebook Shimmer]]></title>
            <link>https://akshayranagujjar.medium.com/skeleton-content-loading-animation-in-android-facebook-shimmer-2a4f155de534?source=rss-460a6b1804bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a4f155de534</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[facebook-shimmer]]></category>
            <category><![CDATA[shimmer-animation]]></category>
            <dc:creator><![CDATA[Akshay Rana GuJJar]]></dc:creator>
            <pubDate>Mon, 29 Jun 2020 18:37:13 GMT</pubDate>
            <atom:updated>2020-06-29T18:37:13.428Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Facebook Shimmer in android" src="https://cdn-images-1.medium.com/max/560/1*D7h9moU7IRBXvUgfLdYEWg.png" /></figure><h3>What is Facebook Shimmer?</h3><p>Today we are going to see what is Facebook shimmer and how to use it?<br>See below example to understand Facebook shimmer.</p><figure><img alt="Facebook shimmer animation" src="https://cdn-images-1.medium.com/max/368/0*3fWGmQvgueYrN8hL.gif" /></figure><p>The Facebook shimmer is used to show or indicate the user that the content is loading from somewhere which takes sometimes so that users need to wait. While content is loading, it is necessary to show the user an indication that content is loading and it is bad practice to leave screen blank which confuses user what is happening in the app or maybe the user thinks the app is hanging.</p><h3>How to use Facebook Shimmer</h3><p>So enough talking, let do some code on how to make content loading animation using facebook shimmer library. See below <strong>facebook shimmer android example</strong></p><p>To use facebook shimmer first we need to add the dependency to your project. See below to add facebook shimmer dependency.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3a9259bd74641fc17556d7b34f45f03/href">https://medium.com/media/e3a9259bd74641fc17556d7b34f45f03/href</a></iframe><p>After adding dependency, let’s create our layout. For demo purposes, we are creating our layout some like below.</p><figure><img alt="Cardview layout for facebook shimmer" src="https://cdn-images-1.medium.com/max/268/0*wM7dXUe_M3fNNKcC.jpg" /></figure><p>To make the above layout we are using this code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46a24eda6c411aa50fbfcddb1c17299c/href">https://medium.com/media/46a24eda6c411aa50fbfcddb1c17299c/href</a></iframe><p>You can make your own layout according to your need.</p><p>Note: we use <a href="https://www.akshayrana.in/2020/06/what-is-cardview-in-android.html">cardview</a> for making this layout you can read here about <a href="https://www.akshayrana.in/2020/06/what-is-cardview-in-android.html">how to use cardview in android</a>.</p><p>After the layout, we need to add code for facebook shimmer effect.</p><p>First, we need to add ShimmerFrameLayout as parent container of the shimmer effect we can simply copy our main layout and with minor changes, we have done with our shimmer layout part. See below code and remember to set the visibility of main layout to gone.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f9eed82a5f3f8f308e0183895118d00/href">https://medium.com/media/8f9eed82a5f3f8f308e0183895118d00/href</a></iframe><p>Notice the ids we have assigned to the ShimmerFrameLayout (facebookShimmerLayout).</p><p>Now, this all for layout part now its time to come to java part.</p><p>Hey I know you are enjoying this article, If you want to read further then you can read it here <a href="https://www.akshayrana.in/2020/02/show-loading-content-animation-facebook.html">Facebook Shimmer Content loading animation</a></p><p>Thank you for reading. Good Luck.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a4f155de534" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recyclerview and Cardview example in Android [Beginner Level]]]></title>
            <link>https://akshayranagujjar.medium.com/recyclerview-and-cardview-example-in-android-beginner-level-45af0ca4a04b?source=rss-460a6b1804bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/45af0ca4a04b</guid>
            <category><![CDATA[android-custom-cardview]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[cardview-and-recyclerview]]></category>
            <category><![CDATA[android-cardview]]></category>
            <category><![CDATA[recyclerview]]></category>
            <dc:creator><![CDATA[Akshay Rana GuJJar]]></dc:creator>
            <pubDate>Sun, 21 Jun 2020 06:45:00 GMT</pubDate>
            <atom:updated>2020-06-22T17:09:18.385Z</atom:updated>
            <content:encoded><![CDATA[<h3>Working with Recyclerview and Cardview</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*4xtdQSWwzvFY__dJ.png" /></figure><p>Hello World, Today we are going to see <a href="https://www.akshayrana.in/2020/06/recyclerview-and-cardview-example-android.html">how we can make a simple recyclerview with cardview in an android studio</a>. In this article, you will learn <a href="https://www.akshayrana.in/2020/06/recyclerview-and-cardview-example-android.html">how to work with recyclerview</a>, what is recyclerview layout manager? See the below gif for understanding what we are going to build.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/179/0*VmjdsB_nZer3VkiF.gif" /></figure><h3>What is Recyclerview in Android?</h3><p>Recyclerview is an advanced version of the listview. It is used to make the repeated view and recycle them to save more memory. Recyclerview is way more efficient than listview. Recyclerview easily handles a large set of views and is very flexible. Recyclerview is like a container that renders a large set of views very efficient manner. Recyclerview is optimized to work with a large number of views and save lots of memory so that your app will freeze or hang the device.</p><p><em>The RecyclerView widget is a more advanced and flexible version of ListView.</em></p><p><em>In the RecyclerView model, several different components work together to display your data. The overall container for your user interface is a RecyclerView object that you add to your layout. The RecyclerView fills itself with views provided by a layout manager that you provide. You can use one of our standard layout managers (such as LinearLayoutManager or GridLayoutManager), or implement your own.</em></p><h3>What is Cardview in Android?</h3><p><a href="https://www.akshayrana.in/2020/06/what-is-cardview-in-android.html">CardView</a> is a widget provided by the android to build a new look and efficient UI. You can make your app look more professional see examples below. <a href="https://www.akshayrana.in/2020/06/what-is-cardview-in-android.html">Cardview</a> is an amazing concept which makes your user experience better than old android UI. Cardview was released with Android version 5.0 which is android lollipop.</p><p>I have already explained <a href="https://www.akshayrana.in/2020/06/what-is-cardview-in-android.html">what is cardview</a>, you can read about it <a href="https://www.akshayrana.in/2020/06/what-is-cardview-in-android.html">here</a>.</p><p>Enough talking now let’s go to the coding part. Yay!</p><h3>Using Cardview in RecyclerView with example</h3><p><a href="https://www.akshayrana.in/2020/06/recyclerview-and-cardview-example-android.html">Making recyclerview with cardview</a> is very simple. We need to follow certain steps which are listed below.</p><h4>Step 1. Add required Dependencies in your project.</h4><p>We use below dependency in our project to <a href="https://www.akshayrana.in/2020/06/recyclerview-and-cardview-example-android.html">use recyclerview and cardview</a>.</p><p>As we are <a href="https://www.akshayrana.in/2020/01/load-image-from-url-in-android.html">loading images from the internet</a> we also use <a href="https://bumptech.github.io/glide/">glide dependency</a> in our project, if you want to learn how to use glide then you can read <a href="https://www.akshayrana.in/2020/01/load-image-from-url-in-android.html">this article</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13f7bb91b24f312590fe8048ba6dc5fc/href">https://medium.com/media/13f7bb91b24f312590fe8048ba6dc5fc/href</a></iframe><h4>Step 2. Make Data Model Class for Holding Data</h4><p>First, we need to make a way to hold data that we are going to use populating in the recyclerview items.</p><p>Make a new java file in the package and we name it as ProfileModel.java.</p><p>And in this file, we add below code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/795cb0ce34dd78836a71ef6ba0b0ea83/href">https://medium.com/media/795cb0ce34dd78836a71ef6ba0b0ea83/href</a></iframe><p>In the above code, we have a class name ProfileModel which has a private string variables firstName, lastName, photo, bottomColor.</p><p>After that, we have a construct with all the variables as parameters to initialize our field variables.</p><p>And then, we make the getter method for each and all the variables to get its values.</p><p>Simple and straight forward.</p><h4>Step 3. Make an item layout file for recyclerview.</h4><p>In this step, we will make a layout for our a single row of recyclerview so that recyclerview uses this layout and make copies of items and add data in the layout if you are unable to understand what I said then don’t worry you will understand later.</p><p>To make the item layout click on the layout folder under res folder in your project and click on new and then click on the layout resource file. We will name this as profile_item and hit enter.</p><p>See below, what our main components for our item layout.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F-4AjLqwJ6Io%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D-4AjLqwJ6Io&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F-4AjLqwJ6Io%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/14cd4b6d225909827b8a0d89e582a4a2/href">https://medium.com/media/14cd4b6d225909827b8a0d89e582a4a2/href</a></iframe><p>We have a cardview as the main container and an imageview that shows the profile picture and a textview to display the name of the person and in the bottom a solid color border to make a decoration in the cardview.</p><p>To make this layout we are using the below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3176f1393c0169e5fe9468900e38174c/href">https://medium.com/media/3176f1393c0169e5fe9468900e38174c/href</a></iframe><p>We specific the height of the cardview and make rounded border any using cardCornerRadius attribute.</p><p>To use multiple views in the cardview we need to have a container layout in the cardview.</p><p>We can’t use cardview as a container we must add a layout for multiple views as child.</p><p>Next is, to make image round or circular we can use cardview and take advantage of cardCornerRadius attribute. Have you noticed in this cardview we are not using and container because we are not using multiple views we are using only ImageView as a child so no need to add any container.</p><p>See also: <a href="https://www.akshayrana.in/2020/06/how-to-save-image-to-storage-using.html"><strong>Save Image to storage using Glide</strong></a></p><p>After that, we added a textview to display name and in the last add a view for showing a border as decoration.</p><p>We have also set the id to all the views for later use.</p><h4>Step 4. Make the Adapter class for recyclerview.</h4><p>In this step, we will make an adapter class that will help to populate the data in the view and make item layout copies in the recyclerview.</p><p>Let’s start by making a new java file and name it as ProfileAdapter.</p><p>After that, we need to extend this class with RecyclerView.Adapter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/548ae63f788f714bfaa777eb265552e0/href">https://medium.com/media/548ae63f788f714bfaa777eb265552e0/href</a></iframe><p>At this point, you will see the error in you code. Don’t worry and keep going with the article.</p><p>Now, we need to create another class for view holder but this one is going to be an inner class of the ProfileAdapter class and this class will extends RecyclerView.ViewHolder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecfeecaf96a9ccbb571c67d2f2dee774/href">https://medium.com/media/ecfeecaf96a9ccbb571c67d2f2dee774/href</a></iframe><p>At this point, you will see an error in the ProfileViewHolder, to resolve this error you need to make a default constructor with the View parameter and call the super constructor. See the below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13a3c61c15bbfb04de8f9b68f023f920/href">https://medium.com/media/13a3c61c15bbfb04de8f9b68f023f920/href</a></iframe><p>Now in the ProfileViewHolder class, we will make declare all the view which we want to populate the data. So we declare an ImageView for the photo, a TextView for user name, and View for bottom line background color.</p><p>After that, we will initialize them in the contractor with their corresponding ids using the itemView variable from constructor parameter. See the below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bdf9d0b58bd1055d594543a66dcb9df3/href">https://medium.com/media/bdf9d0b58bd1055d594543a66dcb9df3/href</a></iframe><p>Now come to adapter class, we made our viewholder class now its time to make use of it in the adapter class as generic as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca27abd57d9543e2d23ecaea86221cf5/href">https://medium.com/media/ca27abd57d9543e2d23ecaea86221cf5/href</a></iframe><p>If you want to continue to read you can go to this link <a href="https://www.akshayrana.in/2020/06/recyclerview-and-cardview-example-android.html">Recyclerview with Cardview example</a></p><p><em>Originally published at </em><a href="https://www.akshayrana.in/2020/06/recyclerview-and-cardview-example-android.html"><em>https://www.akshayrana.in</em></a><em> on June 21, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45af0ca4a04b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Save Image to storage using Glide in Android]]></title>
            <link>https://akshayranagujjar.medium.com/how-to-save-image-to-storage-using-glide-in-android-fa26c842f212?source=rss-460a6b1804bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa26c842f212</guid>
            <category><![CDATA[image-save]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[glide]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Akshay Rana GuJJar]]></dc:creator>
            <pubDate>Fri, 19 Jun 2020 17:15:11 GMT</pubDate>
            <atom:updated>2020-06-19T17:15:11.072Z</atom:updated>
            <content:encoded><![CDATA[<h3>Save Image using Glide</h3><figure><img alt="save Image using Glide" src="https://cdn-images-1.medium.com/max/560/1*5D91ZTobz3nZtIexJc5t8A.png" /><figcaption>save Image using Glide</figcaption></figure><p>Hello World, Today we are going to see how we can <strong>save the image using the Glide library</strong>. Sometimes we are already using glide dependency in our android project to load images from link and we want to download the same image in the android device. In that case, we can utilize glide to save that bitmap to our android storage. Continue reading on this article to see how to download images using <a href="https://bumptech.github.io/glide/">glide dependency</a>.</p><h3>Glide Download Image to File</h3><p>Before we go deep in, I want you to read first <a href="https://www.akshayrana.in/2020/01/load-image-from-url-in-android.html">how to load image from URL using glide</a>. In that article, I have explained how you can use glide in your project.</p><p>Okay, now I am assuming that you know how to use glide to load image from URL.</p><p>I have made this layout to make it easy to understand all the things.</p><figure><img alt="Save Image to storage using Glide" src="https://cdn-images-1.medium.com/max/259/0*VtzXEDiZ2bfLD8jx.png" /><figcaption>Save Image to storage using Glide</figcaption></figure><p>In the above layout, it is self-explanatory but let me explain here is an imageview with a button to download the image on click.</p><p>Let’s see the logic behind the click button. Check the below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91d4bc3ee025402264b493aec593f4d8/href">https://medium.com/media/91d4bc3ee025402264b493aec593f4d8/href</a></iframe><p>In the above code, on the click of a button, we are calling the donwloadImage method which accepts link as a string.</p><p>Below is the code in the donwloadImage method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48149241ede8f7b2f4ebfa1817018920/href">https://medium.com/media/48149241ede8f7b2f4ebfa1817018920/href</a></iframe><p>First, we are verifying whether we have permission to write in internal storage or not.</p><p>Note: Remember to add &lt;<strong>uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE”</strong>/&gt; in your android manifest file.</p><p>The code of verifyPermissions method looks like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1cfe83e95f569b11c448457812377ef/href">https://medium.com/media/f1cfe83e95f569b11c448457812377ef/href</a></iframe><p>Basically, we are checking permission on runtime.</p><p>Now back to the downloadImage method.</p><p>Next, we are taking the folder path where we will save our image and store that value to dirPath variable and then convert it into File Object for later use.</p><p>After that, we are retrieving the file name from the user but you are free to choose whatever you want to be your file name.</p><p>Now comes the main part of this article, we load the image exactly how we load the image using glide but the twist is that as you can see in the into() method we are passing CustomTarget abstract class and implements its methods.</p><p>In the onResourceReady method, we are getting the image as Drawable and then we are converting it in Bitmap.</p><p>Now we have our image as Bitmap and we can perform the saving operation of image.</p><p>After getting the bitmap, we are calling the saveImage method by passing some parameters.</p><p>The first parameter is a bitmap, the second parameter is the directory path as File (which we previously made the variable) and the last and third parameter is file name.</p><p>Let’s see whats in the saveImage method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b7cf48b6fb67b5531ba83bc818541bc/href">https://medium.com/media/1b7cf48b6fb67b5531ba83bc818541bc/href</a></iframe><p>First, we create a directory where we are going to save the image. for that first, we look if the directory already exists or not and if it does not exist then we will make a new directory.</p><p>On successfully directory creation we save that check as boolean in successDirCreated variable and then on the behalf of that perform the actions.</p><p>Hey if you want to read the full story go here <a href="https://www.akshayrana.in/2020/06/how-to-save-image-to-storage-using.html">Save Image to storage using Glide</a></p><p>Thanks for reading all the best.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa26c842f212" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to customize rating bar in android]]></title>
            <link>https://akshayranagujjar.medium.com/how-to-customize-rating-bar-in-android-7837f5fd94d2?source=rss-460a6b1804bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/7837f5fd94d2</guid>
            <category><![CDATA[rating-bar]]></category>
            <category><![CDATA[custom-android]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-rating-bar]]></category>
            <category><![CDATA[custom-rating-bar]]></category>
            <dc:creator><![CDATA[Akshay Rana GuJJar]]></dc:creator>
            <pubDate>Fri, 19 Jun 2020 16:30:27 GMT</pubDate>
            <atom:updated>2020-06-19T16:30:27.787Z</atom:updated>
            <content:encoded><![CDATA[<h3>Custom Rating Bar in Android</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*qgbAS7ZxhDM1dtUn.png" /></figure><p>Hello World, Today we are going to see <strong>how to customize rating bar in android</strong> for example:</p><p>how to make <strong>small rating bar</strong> or how to change the <strong>color of rating bar</strong> or how to completely change rating bar appearance and <strong>set rating change listener</strong> etc.</p><h3>How to change rating bar size or make rating bar small</h3><p>Making a small rating bar is simple but before making a small rating bar, let’s look at how the default rating bar looks if we add it in our layout?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*MtzCFLqS4wU_TAjd.png" /></figure><p>The default rating bar is big and looks ugly, to make it look small and make stars color golden or yellow we use below code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a49860f5e061c6417a11c79fc4e4e27/href">https://medium.com/media/6a49860f5e061c6417a11c79fc4e4e27/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*d4nXQRtr2gJGXpjJ.jpg" /></figure><p>Now, this looks perfect, right? But wait what if I tell you that you can use any image instead of stars in the rating bar? excited! Stay with this article and you will catch it later.</p><p>Now let’s see how we can add a listener to the rating bar do that whenever a user give rating we can at accordingly.</p><h3>Set Listener for Rating bar</h3><p>To add a rating change listener we need to add the below code in our activity java file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f2e79a7cbc01690726e363f1cfca710/href">https://medium.com/media/1f2e79a7cbc01690726e363f1cfca710/href</a></iframe><p>in the first line, we are getting our rating bar widget by using the findViewById method then we are setting the <strong>setOnRatingBarChangeListener</strong> and passing interface in the parameter and implement <strong>onRatingChanged </strong>method and in the parameters, we are getting our rating in float value as the second parameter.</p><p>After getting the rating value by the user we are displaying it in the toast. Of course, you can use this rating according to your need.</p><p>See also: <a href="https://www.akshayrana.in/2020/06/what-is-cardview-in-android.html"><strong>CardView in Android</strong></a></p><h3>Custom Rating Bar in Android</h3><p>By default rating bar shows stars as a rating but there are some cases we need to add our own graphics. Let’s say you want a rating bar instead of stars we need hearts. something like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/0*a6XaWhMaHzWdkf8N.png" /></figure><p>To make a custom rating bar like above. We need to perform certain steps as follows:</p><p>Step 1. Copy your images in the drawable folder and remember image size should be according to the size you want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/0*g1OJzo8GBgoT7bjX.png" /></figure><p>Step 2. Make XML for the rating bar selector in the drawable folder like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/0*jf1Cj0TFsujDyp6z.jpg" /></figure><p>We made two files, one for the fill or highlighted part and one for the empty or un-highlighted part.</p><p>See the below files and their respective code.</p><p>rating_fill.xml for fill part</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98d4bd60004ce594e70e0bf93ec6c5ee/href">https://medium.com/media/98d4bd60004ce594e70e0bf93ec6c5ee/href</a></iframe><p>rating_empty.xml for the empty part.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98f6f8728fc15fc83f2c498478d35c1f/href">https://medium.com/media/98f6f8728fc15fc83f2c498478d35c1f/href</a></iframe><p>Step 3. Now, we have created our selector files, now we need to integrate them together.</p><p>To do that we need to make a new xml file in drawable and write the below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8b00fdf1ed1ed860a1d490c6728d5d3/href">https://medium.com/media/e8b00fdf1ed1ed860a1d490c6728d5d3/href</a></iframe><p>In the above code, we are making a layer list and giving the reference all the above filling and empty selectors.</p><p>Congrats we have completed 90% of work,</p><p>You can read full article here: <a href="https://www.akshayrana.in/2020/06/how-to-customize-rating-bar-in-android.html">Custom Rating Bar in Android</a></p><p>Thanks for reading this article have a good day.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7837f5fd94d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>