diff --git a/filter_an.json b/filter_an.json new file mode 100644 index 0000000000000000000000000000000000000000..bdae57b18b461bd307e22c2b0053b859bbda8320 --- /dev/null +++ b/filter_an.json @@ -0,0 +1,260 @@ +[ + { + "text": "\nTop 7 Google Play Store Tips That You Should Try\n\n\nGoogle Play Store is an official source to download plenty of secure applications, and there are about 3.5 million android applications which are installed by android users and used for some vital purpose in day to day life, including the apps, Google Play Store also let you purchase or download original content ranging from entertaining games, movies, music and a lot of e-books, etc.\n\nEvery android device is incomplete without Google Play Store because there is no other great platform to get secure official apps. But did you know our beloved Google Play Store is not limited to downloading apps?. Besides Top charts and Categories, there are many tricks and tips which could make our tech life easier by managing the apps. Most of the play store tips are related to general settings, let us discuss a few tips below. \n1. Backup Previously Installed Apps\nWhenever a user purchases a new android device and wants to install all the useful apps that were installed in the previous device without keeping track of them. This possible with the help of backup and restoration. Google play store has an option of backup and restores where your app data gets stored in Google drive i.e. 25 MB of installed app data, contacts, call logs, etc.\nBefore using this privilege of backup, make sure that the option of backup and restore is enabled on your device.\nHere\u2019s how you can enable from the settings on home screen:\n\nGo to device Settings from home screen\nTap on the Google\nSelect backup \nSelect backup to Google drive \nNote the Google account used for backup \nApp data is saved and can be restored\n\nLog-in with the same google account on the new device will give an option of installing the apps from previous backup data, there is a point to be noted that the app data can\u2019t be restored only the installed apps are restored. Now all the favorite apps can easily be restored one by one.\n2. Save Mobile Internet Data\nThere might be a situation where the user might be concerned about the internet data package and may try to save internet data while installing or updating apps through mobile data, because some large app installations like game updates may consume more data and end finishing your data usage limit then this may lead to other congestion. \nThe solution is to change the general settings of app download preferences, auto-update apps, and auto-play videos, which are by default set to consume internet data without permission, here the user can change the preferences accordingly. To achieve this ability, tap on the Google play store app and proceed to settings section then to general settings and find three options named,\n\nApp download preference > change to over WiFi only\nAuto-update apps > change to don\u2019t auto-update apps\nAuto-play videos > change to don\u2019t auto-play videos\n\nNow the apps can be downloaded through WiFi or any other user preference with the control of data usage.\n3. Install Android Apps on Your Chromebook\nUser can download and use android apps on Chromebook using the Google play store app. Firstly there are few steps that are to be followed to install android apps on Chromebook, \n\nMake sure that Chromebook software is updated\nLook for Google play store if it\u2019s provided by OS\nTap on Google play store\nLook for Install apps and games from Google Play on Chromebook.\nIf the above option is not found, then that Chromebook doesn\u2019t work with Android apps\nIn the window, select More\nUser will be prompted to agree the Terms of Service.\nSelect I Agree\nFind and download Android apps on Chromebook.\n\n4. Restrict Inappropriate App Downloads\nThere are few apps with age restrictions and copyright, precautions are to be taken by parents towards children who are under aged because this may lead to misuse of the apps on play store like playing games which contain violence and misuse dating apps which leak privacy.\nTo avoid this problem there is an option called \u201cparental control\u201d through which parental lock is enabled on play store apps, this can be achieved by enabling the \u201cparental controls\u201d section in the user control area of settings, Above are the steps to find:\n\nopen the Play Store and then menu.\nGo to Settings\nTap on Parental controls \nChange to ON\nSet parental lock PIN code.\nSelect the list of things that can be downloaded and restricted.\n\nOnce the restrictions are set, whenever the child tries to install some new inappropriate app has to enter the PIN to download, unless that the app won\u2019t be downloaded.\n5. Try New Apps Before Release\nTo get user feedback, some developers make new apps or features available before they\u2019re officially released to the general public.The user can try these apps or features by joining early access or beta programs. These apps may be less stable or also may crash sometimes. Some apps set a limit on the number of users in early access and beta programs. If there\u2019s no more space user will be prompted with a message saying \u201cfull\u201d. Steps to find and join an early access app:\n\nOpen the Google Play Store \nAt the end of the list find Top charts and tap Early access.\nFind an app that gives early access\nTap Install\nUse the app and leave a feedback\n\n6. Download Play Store Apps From PC\nUsers can also download apps on mobile devices from the PC version of the Google play store, it\u2019s easy to do this by logging onto the Google account on PC and go to the web version of the play store, search for the desired app and install it.\nAfter this find a menu list containing all the devices that are connected using the same account, select the device name on which the app has to be installed. The mobile device must be enabled with the internet to start the download.\n7. Customize Theme\nIf a user doesn\u2019t like using bright screen while surfing through play store then there is an option of changing theme based on user preference.\nFor this feature tap on play store and proceed to settings and then to Theme, select Dark theme, light theme or leave it to set by battery saver.\n" + }, + { + "text": "\nSingleton Class in Kotlin\n\n\nSingleton Class in Kotlin is also called as the Singleton Object in Kotlin. Singleton class is a class that is defined in such a way that only one instance of the class can be created and used everywhere. Many times we create the two different objects of the same class, but we have to remember that creating two different objects also requires the allocation of two different memories for the objects. So it is better to make a single object and use it again and again.\u00a0\n\n\nKotlin\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n// Kotlin program \nfun main(args: Array)\u00a0 \n{ \n\u00a0\u00a0val obj1 = GFG() \n\u00a0\u00a0val obj2 = GFG() \n\u00a0\u00a0println(obj1.toString()) \n\u00a0\u00a0println(obj2.toString()) \n} \n\u00a0\u00a0\nclass GFG \n{ \n\u00a0\u00a0\u00a0\u00a0\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nOutput:\n\nIn the above example, we can see that both the objects have a different address, thus it is a wastage of memory. In the below program, we have done the same thing, but we have used the singleton class.\n\n\nKotlin\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n// Kotlin program \nfun main(args: Array) \n{ \n\u00a0\u00a0println(GFG.toString()) \n\u00a0\u00a0println(GFG.toString()) \n} \n\u00a0\u00a0\n// GFG is the singleton class here \nobject\u00a0 GFG \n{ \n\u00a0\u00a0\u00a0\u00a0\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nOutput:\n\nSo when we use an object instead of a class, Kotlin actually uses the Singelton and allocates the single memory. In Java, a singleton class is made making a class named Singleton. But in Kotlin, we need to use the object keyword. The object class can have functions, properties, and the init method. The constructor method is not allowed in an object so we can use the init method if some initialization is required and the object can be defined inside a class. We call the method and member variables present in the singleton class using the class name, as we did in the companion objects.\n\n\nKotlin\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n// Kotlin program \nfun main(args: Array)\u00a0 \n{ \n\u00a0\u00a0println(GFG.name) \n\u00a0\u00a0println(\"The answer of addition is ${GFG.add(3,2)}\") \n\u00a0\u00a0println(\"The answer of addition is ${GFG.add(10,15)}\") \n} \n\u00a0\u00a0\nobject\u00a0 GFG \n{ \n\u00a0\u00a0\u00a0init\u00a0 \n\u00a0\u00a0{ \n\u00a0\u00a0\u00a0\u00a0println(\"Singleton class invoked.\") \n\u00a0\u00a0} \n\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0var name = \"GFG Is Best\"\n\u00a0\u00a0fun add(num1:Int,num2:Int):Int \n\u00a0\u00a0{ \n\u00a0\u00a0\u00a0\u00a0return num1.plus(num2)\u00a0 \n\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nOutput: \u00a0\n\nProperties of Singleton Class\nThe following are the properties of a typical singleton class:\n\nOnly one instance: The singleton class has only one instance and this is done by providing an instance of the class, within the class.\nGlobally accessible: The instance of the singleton class should be globally accessible so that each class can use it.\nConstructor not allowed: We can use the init method to initialize our member variables.\n\nImportance of Singleton Objects In Android\u00a0\nBelow are some points which explain the importance of singleton objects in android along with some examples, where it must be used, and reasons for why android developers should learn about singleton objects.\n\nAs we know that when we want a single instance of a particular object for the entire application, then we use Singleton. Common use-cases when you use the singleton is when you use Retrofit for every single request that you make throughout the app, in that case, you only need the single instance of the retrofit, as that instance of the retrofit contains some properties attached to it, like Gson Converter(which is used for conversion of JSON response to Java Objects) and Moshy Converter, so you want to reuse that instance and creating a new instance again and again would be a waste of space and time, so in this case, we have to use singleton objects.\nConsider the case when you are working with the repository in MVVM architecture, so in that case, you should only create only 1 instance of the repository, as repositories are not going to change, and creating different instances would result in space increment and time wastage.\nSuppose you have an app, and users can Login to it after undergoing user authentication, so if at the same time two user with same name and password tries to Login to the account, the app should not permit as due to concern of security issues. So singleton objects help us here to create only one instance of the object, i.e user here so that multiple logins can\u2019t be possible. Hope these examples are sufficient to satisfy the reader to explore more about singleton objects in Kotlin so that they can use singleton object in their android projects.\n\nSample Android Program showing Use of Singleton Object:\n\n\nKotlin\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n// sample android application program in kotlin \n// showing use of singleton object \npackage com.example.retrofitexample \nimport retrofit2.Call \nimport retrofit2.Retrofit \nimport retrofit2.converter.gson.GsonConverterFactory \nimport retrofit2.http.GET \nimport retrofit2.http.Query \n\u00a0\u00a0\nconst val\u00a0 BASE_URL = \"https://newsapi.org/\"\nconst val API_KEY = \"ff30357667f94aca9793cc35b9e447c1\"\n\u00a0\u00a0\ninterface NewsInterface \n{ \n\u00a0\u00a0\u00a0\u00a0@GET(\"v2/top-headlines?apiKey=$API_KEY\") \n\u00a0\u00a0\u00a0\u00a0fun getheadlines(@Query(\"country\")country:String,@Query(\"page\")page:Int):Call \n\u00a0\u00a0\u00a0\u00a0// function used to get the headlines of the country according to the query\u00a0 \n\u00a0\u00a0\u00a0\u00a0// written by developer \n} \n\u00a0\u00a0\n// NewsService is the instance of retrofit made by using Singleton object \nobject\u00a0 NewsService \n{ \n\u00a0\u00a0\u00a0\u00a0val newsInstance:NewsInterface \n\u00a0\u00a0\u00a0\u00a0init { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val retrofit=Retrofit.Builder() \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.baseUrl(BASE_URL) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.addConverterFactory(GsonConverterFactory.create()) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.build() \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0newsInstance=retrofit.create(NewsInterface::class.java) \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + }, + { + "text": "\nHow to Create AlertDialog Box Using SweetAlert Dialog Library in Android?\n\n\nIn this article, we will learn about how to add Custom Alert Dialog in an app using the SweetAlert Dialog Library. It is a pop-up box that appears in response to any action of the user. AlertBox is very useful when it comes to validation, it can be used to display confirmation messages. Suppose the user presses the Back Button without saving the changes then for warning it can be used. When the transaction is done in payment apps a short Dialog Box can be shown to the user describing the transaction\u2019s status.\nAdvantages:\n\nIt provides us with an excellent user interface which makes the user experience very good.\nIt makes the work much easier so it is used over Custom Dialog, which needs the whole layout to be created.\nIt provides many different types of layouts for the dialog box.\n\nStep by Step Implementation\nStep 1: Create a New Project in Android Studio\nTo create a new project in Android Studio please refer to\u00a0How to Create/Start a New Project in Android Studio. The code for that has been given in both Java and Kotlin Programming Language for Android.\nStep 2: Adding Dependency to the build.gradle File\n\u00a0Go to Module build.gradle file and add this dependency and click on Sync Now button.\nimplementation 'com.github.f0ris.sweetalert:library:1.5.1'\nStep 3: Working with the XML Files\nNext, go to the activity_main.xml file, which represents the UI of the project. Below is the code for the\u00a0activity_main.xml file. Comments are added inside the code to understand the code in more detail.\n\n\nXML\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStep 4: Working with the MainActivity File\nGo to the MainActivity File and refer to the following code. Below is the code for the MainActivity File. Comments are added inside the code to understand the code in more detail.\n\n\nJava\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport androidx.appcompat.app.AppCompatActivity; \nimport android.os.Bundle; \nimport android.view.View; \nimport cn.pedant.SweetAlert.SweetAlertDialog; \n\u00a0\u00a0\npublic class MainActivity extends AppCompatActivity { \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0protected void onCreate(Bundle savedInstanceState) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main); \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0public void showDialog(View view) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0switch (view.getId()) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0case R.id.basic_dialog: \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new SweetAlertDialog(this) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setTitleText(\"Here's a message!\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setContentText(\"This is Basic Dialog\").show(); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break; \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0case R.id.error_dialog: \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setTitleText(\"Oops...\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setContentText(\"Something went wrong!\").show(); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break; \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0case R.id.warning_dialog: \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setTitleText(\"Are you sure?\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setContentText(\"Won't be able to recover this file !\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setConfirmText(\"Yes, delete it!\").show(); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break; \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0case R.id.success_dialog: \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setTitleText(\"Great!\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setContentText(\"You completed this task.\").show(); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break; \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0case R.id.custom_dialog: \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setTitleText(\"Android\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setContentText(\"This is custom dialog\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setCustomImage(R.drawable.ic_android_black).show(); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break; \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nKotlin\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport android.os.Bundle \nimport android.view.View \nimport androidx.appcompat.app.AppCompatActivity \nimport cn.pedant.SweetAlert.SweetAlertDialog \n\u00a0\u00a0\nclass MainActivity : AppCompatActivity() { \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0override fun onCreate(savedInstanceState: Bundle?) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main) \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0fun showDialog(view: View) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0when (view.id) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0R.id.basic_dialog -> SweetAlertDialog(this) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setTitleText(\"Here's a message!\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setContentText(\"This is Basic Dialog\").show() \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0R.id.error_dialog -> SweetAlertDialog(this, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0SweetAlertDialog.ERROR_TYPE).setTitleText(\"Oops...\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setContentText(\"Something went wrong!\").show() \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0R.id.warning_dialog -> SweetAlertDialog(this, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0SweetAlertDialog.WARNING_TYPE).setTitleText(\"Are you sure?\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setContentText(\"Won't be able to recover this file !\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setConfirmText(\"Yes, delete it!\").show() \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0R.id.success_dialog -> SweetAlertDialog(this, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0SweetAlertDialog.SUCCESS_TYPE).setTitleText(\"Great!\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setContentText(\"You completed this task.\").show() \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0R.id.custom_dialog -> SweetAlertDialog(this, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0SweetAlertDialog.CUSTOM_IMAGE_TYPE).setTitleText(\"Android\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setContentText(\"This is custom dialog\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setCustomImage(R.drawable.ic_android_black).show() \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nOutput:\n\nhttps://media.geeksforgeeks.org/wp-content/uploads/20200704233631/Record_2020-07-04-23-31-58_ebd0f40a3163df3b2fbe902630069a421.mp4\n\n" + }, + { + "text": "\nTheming Material Design Snackbars in Android with Example\n\n\nIn the previous article, it\u2019s been discussed Snackbar Material Design Components in Android. In this article, it\u2019s been discussed how we can theme material design Snackbar and increase the User Experience.\nTheming Example 1:\n\nThis method is done using the styles.xml file. Where we need to override the default style of the Snackbar.\nHave a look at the following image to get what all the things can be customized on the Snackbar.\n\n\n\nBy implementing this method all the Snackbars get affected by these style attributes.\nIn this customization, the background tint and the action button text color is changed.\nThis makes the user focus on the action and they can do the desired action according to the message shown on the Snackbar.\nThis also prevents user the unnecessary clicking on the action button.\n\n\n\nXML\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nOutput: Run on Emulator\n\nhttps://media.geeksforgeeks.org/wp-content/uploads/20201102185421/GFG_nexus_5.mp4\nTheming Example 2:\n\nThis method of implementation makes changes to only the particular Snackbar and not for all the Snackbars.\nThe same can be achieved by setting all the things programmatically.\nNow working with MainActivity.java file.\n\n\n\nJava\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport androidx.appcompat.app.AppCompatActivity;\nimport android.os.Bundle;\nimport android.view.View;\nimport android.widget.Button;\nimport android.widget.Toast;\nimport com.google.android.material.snackbar.Snackbar;\n\u00a0\npublic class MainActivity extends AppCompatActivity {\n\u00a0\n\u00a0\u00a0\u00a0\u00a0// Button to show the snackbar\n\u00a0\u00a0\u00a0\u00a0Button bShowSnackbar;\n\u00a0\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0protected void onCreate(Bundle savedInstanceState) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main);\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// register the show snackbar button with the\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// appropriate ID\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0bShowSnackbar = findViewById(R.id.show_snackbar_button);\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// button click listener to show the snackbar\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0bShowSnackbar.setOnClickListener(new View.OnClickListener() {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public void onClick(View v) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// pass the mSnackbarLayout as the view\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// to the make function\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Snackbar snackbar = Snackbar.make(v, \"You have deleted an item\", Snackbar.LENGTH_LONG);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0snackbar.setAction(\"UNDO\", new View.OnClickListener() {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public void onClick(View v) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// perform any action when the button on the snackbar is clicked here in this case it\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// shows a simple toast\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Toast.makeText(MainActivity.this, \"The item has been restored\", Toast.LENGTH_SHORT).show();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// the duration is in terms of milliseconds\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0snackbar.setDuration(3000);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// set the background tint color for the snackbar\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0snackbar.setBackgroundTint(getResources().getColor(R.color.colorPrimary));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// set the action button text color of the snackbar however this is optional\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// as all the snackbar wont have the action button\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0snackbar.setActionTextColor(getResources().getColor(R.color.actionTextColorForSnackbar));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0snackbar.show();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\n\u00a0\u00a0\u00a0\u00a0}\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nKotlin\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport androidx.appcompat.app.AppCompatActivity;\nimport android.os.Bundle;\nimport android.view.View;\nimport android.widget.Button;\nimport android.widget.Toast;\nimport com.google.android.material.snackbar.Snackbar;\n\u00a0\nclass MainActivity : AppCompatActivity() {\n\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0// Button to show the snackbar\n\u00a0\u00a0\u00a0\u00a0var bShowSnackbar: Button? = null\n\u00a0\u00a0\u00a0\u00a0override fun onCreate(savedInstanceState: Bundle?) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main)\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// register the show snackbar button with the\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// appropriate ID\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0bShowSnackbar = findViewById(R.id.show_snackbar_button)\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// button click listener to show the snackbar\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0bShowSnackbar.setOnClickListener(object : OnClickListener() {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0fun onClick(v: View?) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// pass the mSnackbarLayout as the view\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// to the make function\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val snackbar = Snackbar.make(v, \"You have deleted an item\", Snackbar.LENGTH_LONG)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0snackbar.setAction(\"UNDO\", object : OnClickListener() {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0fun onClick(v: View?) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// perform any action when the button on the snackbar is clicked here in this case it\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// shows a simple toast\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Toast.makeText(\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this@MainActivity,\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"The item has been restored\",\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Toast.LENGTH_SHORT\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0).show()\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0})\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// the duration is in terms of milliseconds\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0snackbar.duration = 3000\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// set the background tint color for the snackbar\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0snackbar.setBackgroundTint(resources.getColor(R.color.colorPrimary))\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// set the action button text color of the snackbar however this is optional\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// as all the snackbar wont have the action button\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0snackbar.setActionTextColor(resources.getColor(R.color.actionTextColorForSnackbar))\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0snackbar.show()\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0})\n\u00a0\u00a0\u00a0\u00a0}\n}\n//This code is written by Ujjwal Kumar Bhardwaj\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nOutput: Run on Emulator\nhttps://media.geeksforgeeks.org/wp-content/uploads/20201102190417/GFG_nexus_5.mp4\nTheming Example 3:\n\nChanging the animation mode of the Snackbar.\nThis increases the User Experience too, also by changing the animation of the entering and exit of the Snackbar makes the user focus on the message they got on Snackbar and perform the action according to the message.\nHave a look at the following image to get the difference between the animation modes of the Snackbar.\n\n\n\nThe material design offers two types of animation modes for the Snackbar. One is fade animation (which is the default) and the second is the slide animation.\nThe following code must be invoked inside the styles.xml file. In this case, the Snackbar animation mode is set as a slide.\n\n\n\nXML\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nOutput: Run on Emulator\nhttps://media.geeksforgeeks.org/wp-content/uploads/20201102194451/GFG_back_frame.mp4\n\n" + }, + { + "text": "\nDynamic ImageSwitcher in Kotlin\n\n\nAndroid ImageSwitcher is a user interface widget that provides a smooth transition animation effect to the images while switching between them to display in the view.\nImageSwitcher is subclass of View Switcher which is used to animates one image and displays next one.\nHere, we create ImageSwitcher programmatically in Kotlin file.\nFirst we create a new project by following the below steps:\n\nClick on File, then New => New Project.\nAfter that include the Kotlin support and click on next.\nSelect the minimum SDK as per convenience and click next button.\nThen select the Empty activity => next => finish.\n\nModify activity_main.xml file\nIn this file, we use constraint layout with ImageSwitcher and Buttons.\n\nXML\n\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nUpdate strings.xml file\nHere, we update the name of the application using the string tag.\n\nXML\n\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\u00a0\u00a0\u00a0ImageSwitcherInKotlin \n\u00a0\u00a0\u00a0Next \n\u00a0\u00a0\u00a0Prev \n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + }, + { + "text": "\nCustomArrayAdapter in Android with Example\n\n\nIn Android, ArrayAdapters are used for populating and controlling the ListView and Spinners. ArrayAdapter by default provides ListItems that include only single information or single TextView. In order to have a more complex layout that includes multiple information in a single ListItem such as images, text, etc. we use CustomArrayAdapter. Apps like Instagram, WhatsApp, and many more are using such a complex layout.\nExample\nIn this example, we are going to make an app for different versions of Android OS which is having an ImageView and a TextView which shows the version name. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language.\n\nStep by Step Implementation\nStep 1: Create a New Project\nTo create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. . Note that select Java as the programming language.\nStep 2: Working with the activity_main.xml file\nIn this step, we will add a ListView to our activity_main.xml file which is used to show the data of listItems. Go to the app > res > layout > activity_main.xml and the following code snippet.\n\n\nXML\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nBefore moving further let\u2019s add some color attributes in order to enhance the app bar. Go to app > res > values > colors.xml and add the following color attributes.\u00a0\n\nXML\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\u00a0 \n\u00a0\u00a0\u00a0\u00a0#0F9D58\u00a0 \n\u00a0\u00a0\u00a0\u00a0#16E37F\u00a0 \n\u00a0\u00a0\u00a0\u00a0#03DAC5\u00a0 \n\u00a0 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStep 3: Create a new layout file list_item.xml\nIn this step, we will create a layout file for the single list item view. Go to app > res > layout > right-click > New > Layout Resource File and name it as list_item. list_item.xml contains an ImageView and a TextView which is used for populating the ListView.\n\n\nXML\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStep 4: Create a new Java class Item.java\nWe will create a new java class and name it as Item. Item.java contains three private member variables androidVersionImage, androidVersionName, androidVersionNumber. Later on, we will create an ArrayList of this Item type. Go to app > java > package > right-click > create new java class.\n\n\nJava\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\npublic class Item { \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0private int androidVersionImage; \n\u00a0\u00a0\u00a0\u00a0private String androidVersionName; \n\u00a0\u00a0\u00a0\u00a0private String androidVersionNumber; \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0// Constructor \n\u00a0\u00a0\u00a0\u00a0public Item(int androidVersionImage, String androidVersionName, String androidVersionNumber) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.androidVersionImage = androidVersionImage; \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.androidVersionName = androidVersionName; \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.androidVersionNumber = androidVersionNumber; \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0// Getters and Setters method \n\u00a0\u00a0\u00a0\u00a0public int getAndroidVersionImage() { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return androidVersionImage; \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0public void setAndroidVersionImage(int androidVersionImage) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.androidVersionImage = androidVersionImage; \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0public String getAndroidVersionName() { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return androidVersionName; \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0public void setAndroidVersionName(String androidVersionName) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.androidVersionName = androidVersionName; \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0public String getAndroidVersionNumber() { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return androidVersionNumber; \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0public void setAndroidVersionNumber(String androidVersionNumber) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.androidVersionNumber = androidVersionNumber; \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStep 5: Creating Adapter class\nNow, we will create an Adapter class that acts as a bridge between the UI Component and the Data Source .i.e., androidVersionImage, androidVersionName, androidVersionNumber, and ListView. Go to the app > java > package > right-click and create a new java class and name it as Adapter. Below is the code snippet is given for it.\n\n\nJava\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport android.content.Context; \nimport android.view.LayoutInflater; \nimport android.view.View; \nimport android.view.ViewGroup; \nimport android.widget.ArrayAdapter; \nimport android.widget.ImageView; \nimport android.widget.TextView; \nimport java.util.ArrayList; \n\u00a0\u00a0\npublic class Adapter extends ArrayAdapter { \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0ImageView imageView; \n\u00a0\u00a0\u00a0\u00a0TextView textView1, textView2; \n\u00a0\u00a0\u00a0\u00a0ArrayList androidVersionList = new ArrayList <>(); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0public Adapter(Context context, int textViewResourceId, ArrayList objects) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super(context, textViewResourceId, objects); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0androidVersionList = objects; \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0// Returns total number of items to be displayed in the list. \n\u00a0\u00a0\u00a0\u00a0// It counts the value from the arraylist size \n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0public int getCount() { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return super.getCount(); \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0// This function implicitly gets called when the listItem view is ready \n\u00a0\u00a0\u00a0\u00a0// to be displayed. Here we set the layout and add data to the views \n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0public View getView(int position, View convertView, ViewGroup viewGroup) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0View view = convertView; \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Setting layout \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0view = layoutInflater.inflate(R.layout.list_item, null); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0imageView = (ImageView) view.findViewById(R.id.androidVersionImage); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0textView1 = (TextView) view.findViewById(R.id.androidVersionName); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0textView2 = (TextView) view.findViewById(R.id.androidVersionNumber); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Adding data to the Views \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0imageView.setImageResource(androidVersionList.get(position).getAndroidVersionImage()); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0textView1.setText(androidVersionList.get(position).getAndroidVersionName()); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0textView2.setText(androidVersionList.get(position).getAndroidVersionNumber()); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return view; \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStep 6: Working with the MainActivity.java file\nIn MainActivity.java class we create an ArrayList for storing images and texts. These images are placed in the drawable folder(app > res > drawable). You can use any images in place of this. We get the reference of listView and set the adapter on the listView.\n\n\nJava\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport androidx.appcompat.app.AppCompatActivity; \nimport android.os.Bundle; \nimport android.widget.ListView; \nimport java.util.ArrayList; \n\u00a0\u00a0\npublic class MainActivity extends AppCompatActivity { \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0ListView listView; \n\u00a0\u00a0\u00a0\u00a0ArrayList androidVersionList = new ArrayList <>(); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0protected void onCreate(Bundle savedInstanceState) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Getting the reference of listView \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0listView = (ListView) findViewById(R.id.listView); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Adding image and texts to list \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0androidVersionList.add(new Item(R.drawable.donut, \"Donut\", \"1.6\")); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0androidVersionList.add(new Item(R.drawable.eclair, \"Eclair\", \"2.0 - 2.1\")); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0androidVersionList.add(new Item(R.drawable.froyo, \"Froyo\", \"2.2 - 2.2.3\")); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0androidVersionList.add(new Item(R.drawable.gingerbread, \"GingerBreak\", \"2.3 - 2.3.7\")); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0androidVersionList.add(new Item(R.drawable.honeycomb, \"HoneyComb\", \"3.0 - 3.2.6\")); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0androidVersionList.add(new Item(R.drawable.icecream, \"IceCream\", \"4.0 - 4.0.4\")); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0androidVersionList.add(new Item(R.drawable.jellybean, \"JellyBean\", \"4.1 - 4.3.1\")); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0androidVersionList.add(new Item(R.drawable.kitkat, \"KitKat\", \"4.4 - 4.4.4\")); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0androidVersionList.add(new Item(R.drawable.lollipop, \"Lollipop\", \"5.0 - 5.1.1\")); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0androidVersionList.add(new Item(R.drawable.marshmallow, \"Marshmallow\", \"6.0 - 6.0.1\")); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Adapter adapter = new Adapter(this, R.layout.list_item, androidVersionList); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Setting the adapter to list \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0listView.setAdapter(adapter); \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nOutput: Run On Emulator\u00a0\n\n\n" + }, + { + "text": "\nHow to Build a Video Calling Android App with Jitsi Meet SDK?\n\n\nVideo Calling becomes a most demanding feature in many social media apps like WhatsApp, Instagram, Facebook, etc. Not only this but also there are some other applications available for providing only this feature to connect people all over the world with each other like Duo. Hence, this gives an idea to us about the importance of video calling. So in this article, we will develop our own Video Calling application using Jitsi. Now, without wasting further time let\u2019s look at the implementation of this Video Calling application in Android.\u00a0\nWhat we are going to build in this article?\u00a0\nIn this article, we will develop a sample application that will contain an EditText and a Button in its MainActivity. Using EditText we will name a room for us to video calling and after that, by clicking the Button we will join that room and a new activity will open by the name of our created room, and finally, by using this activity we will do video calling. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to\u00a0implement this project using the\u00a0Java\u00a0language.\u00a0\n\nhttps://media.geeksforgeeks.org/wp-content/uploads/20210126163141/gfg_output.mp4\nStep by Step Implementation of \u00a0Video Calling Application using Jitsi Meet SDK\nStep 1: Create a New Project\nTo create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language. Select the minimum SDK 21 or higher.\nStep 2: Add jitsi maven repository\nNow, go to the root build.gradle(Project) and add these lines at the end of repositories below the jcenter() inside the allprojects{ } section.\n\nallprojects {\n\u00a0repositories {\n\u00a0 \u00a0\u2026\n\u00a0 \u00a0maven { url \u201chttps://github.com/jitsi/jitsi-maven-repository/raw/master/releases\u201d }\n\u00a0 \u00a0 \u00a0}\n}\n\nStep 3: Add dependency\nNow, Navigate to the Gradle Scripts > build.gradle(Module:app) add the below dependency in the dependencies section.\u00a0\n\nimplementation(\u2018org.jitsi.react:jitsi-meet-sdk:2.9.0\u2019) { transitive = true }\u00a0\n\nStep 4: Add java 1.8 compatibility support in build.gradle(Module:app)\u00a0\nNow, to add java 1.8 compatibility support to the project paste these lines below buildTypes {} inside the android { } tag if already not present there.\n\ncompileOptions {\n\u00a0 \u00a0sourceCompatibility JavaVersion.VERSION_1_8\n\u00a0 \u00a0targetCompatibility JavaVersion.VERSION_1_8\n}\n\nStep 5: Add proguard rules\nNow, we will add some proguard rules, so go to the Gradle Scripts > proguard-rules.pro and paste the following lines.\n\nReference: https://github.com/jitsi/jitsi-meet/blob/master/android/app/proguard-rules.pro\n\n# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt\n# You can edit the include path and order by changing the proguardFiles\n# directive in build.gradle.\n#\n# For more details, see\n# http://developer.android.com/guide/developing/tools/proguard.html\n\n# Add any project specific keep options here:\n\n# React Native\n\n# Keep our interfaces so they can be used by other ProGuard rules.\n# See http://sourceforge.net/p/proguard/bugs/466/\n-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip\n-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters\n-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip\n\n# Do not strip any method/class that is annotated with @DoNotStrip\n-keep @com.facebook.proguard.annotations.DoNotStrip class *\n-keep @com.facebook.common.internal.DoNotStrip class *\n-keepclassmembers class * {\n @com.facebook.proguard.annotations.DoNotStrip *;\n @com.facebook.common.internal.DoNotStrip *;\n}\n\n-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {\n void set*(***);\n *** get*();\n}\n\n-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }\n-keep class * extends com.facebook.react.bridge.NativeModule { *; }\n-keepclassmembers,includedescriptorclasses class * { native ; }\n-keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; }\n-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; }\n-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; }\n\n-dontwarn com.facebook.react.**\n-keep,includedescriptorclasses class com.facebook.react.bridge.** { *; }\n\n# okhttp\n\n-keepattributes Signature\n-keepattributes *Annotation*\n-keep class okhttp3.** { *; }\n-keep interface okhttp3.** { *; }\n-dontwarn okhttp3.**\n\n# okio\n\n-keep class sun.misc.Unsafe { *; }\n-dontwarn java.nio.file.*\n-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement\n-keep class okio.** { *; }\n-dontwarn okio.**\n\n# WebRTC\n\n-keep class org.webrtc.** { *; }\n-dontwarn org.chromium.build.BuildHooksAndroid\n\n# Jisti Meet SDK\n\n-keep class org.jitsi.meet.** { *; }\n-keep class org.jitsi.meet.sdk.** { *; }\n\n# We added the following when we switched minifyEnabled on. Probably because we\n# ran the app and hit problems...\n\n-keep class com.facebook.react.bridge.CatalystInstanceImpl { *; }\n-keep class com.facebook.react.bridge.ExecutorToken { *; }\n-keep class com.facebook.react.bridge.JavaScriptExecutor { *; }\n-keep class com.facebook.react.bridge.ModuleRegistryHolder { *; }\n-keep class com.facebook.react.bridge.ReadableType { *; }\n-keep class com.facebook.react.bridge.queue.NativeRunnable { *; }\n-keep class com.facebook.react.devsupport.** { *; }\n\n-dontwarn com.facebook.react.devsupport.**\n-dontwarn com.google.appengine.**\n-dontwarn com.squareup.okhttp.**\n-dontwarn javax.servlet.**\n\n# ^^^ We added the above when we switched minifyEnabled on.\n\n# Rule to avoid build errors related to SVGs.\n-keep public class com.horcrux.svg.** {*;}\nNote:\nsun.misc.Unsafe: This package was removed in Java 9 and later versions, it\nis considered as a low-level memory access package, it is best to avoid it \nand use the more reliable java.util.concurrent package for synchronization.\nFinally, sync your project and now we have everything which we will need during implementation so now, move towards its implementation. \u00a0\nStep 6: Working with the activity_main.xml file\nNow it\u2019s time to design the layout of the application. So for that go-to the app >res > layout > activity_main.xml and paste the below-written code in the activity_main.xml file.\u00a0\n\n\nXML\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStep 7: Working with the MainActivity.java file\nGo to the app > java > package name > MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.\n\n\nJava\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport android.os.Bundle;\nimport android.view.View;\nimport android.widget.EditText;\n\u00a0\nimport androidx.appcompat.app.AppCompatActivity;\n\u00a0\nimport org.jitsi.meet.sdk.JitsiMeetActivity;\nimport org.jitsi.meet.sdk.JitsiMeetConferenceOptions;\n\u00a0\nimport java.net.MalformedURLException;\nimport java.net.URL;\n\u00a0\npublic class MainActivity extends AppCompatActivity {\n\u00a0\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0protected void onCreate(Bundle savedInstanceState) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// using try catch block to handle exceptions\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0try {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// object creation of JitsiMeetConferenceOptions\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// class by the name of options\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0JitsiMeetConferenceOptions options = new JitsiMeetConferenceOptions.Builder()\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setServerURL(new URL(\"\"))\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setWelcomePageEnabled(false)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.build();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} catch (MalformedURLException e) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0e.printStackTrace();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0// we have declared the name of onButtonClick() method \n\u00a0\u00a0\u00a0\u00a0// in our xml file\u00a0 now we are going to define it.\n\u00a0\u00a0\u00a0\u00a0public void onButtonClick(View v) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// initialize editText with method findViewById()\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// here editText will hold the name of room which is given by user\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0EditText editText = findViewById(R.id.conferenceName);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// store the string input by user in editText in \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// an local variable named text of string type\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0String text = editText.getText().toString();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// if user has typed some text in \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// EditText then only room will create \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (text.length() > 0) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// creating a room using\u00a0 JitsiMeetConferenceOptions class \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// here .setRoom() method will set the text in room name\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// here launch method with launch a new room to user where\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// they can invite others too.\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0JitsiMeetConferenceOptions options\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0= new JitsiMeetConferenceOptions.Builder()\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.setRoom(text)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.build();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0JitsiMeetActivity.launch(this, options);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0}\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nThat\u2019s all, now the video calling application is ready to install on the device. Here is what the output of the application looks like.\nOutput: Run on Physical Device\nhttps://media.geeksforgeeks.org/wp-content/uploads/20210126163141/gfg_output.mp4\nGithub Link: For further help go through this repository.\u00a0\n\n" + }, + { + "text": "\nSpinner in Android with Example\n\n\nAndroid Spinner is a view similar to the dropdown list which is used to select one option from the list of options. It provides an easy way to select one item from the list of items and it shows a dropdown list of all values when we click on it. The default value of the android spinner will be the currently selected value and by using Adapter we can easily bind the items to the spinner objects. Generally, we populate our Spinner control with a list of items by using an ArrayAdapter in our Kotlin file.\u00a0\nDifferent Attributes for Spinner Widget\n\n\n\n\nXML attributes\nDescription\n\n\n\n\nandroid:id\nUsed to specify the id of the view.\n\n\nandroid:textAlignment\nUsed to the text alignment in the dropdown list.\n\n\nandroid:background\nUsed to set the background of the view.\n\n\nandroid:padding\nUsed to set the padding of the view.\n\n\nandroid:visibility\nUsed to set the visibility of the view.\n\n\nandroid:gravity\nUsed to specify the gravity of the view like center, top, bottom, etc\n\n\n\n\nExample to demonstrate the Spinner\nHere is an example of an Android application that displays the list of courses of GFG. Use ArrayAdapter to store the courses list. Create a single MainActivity that contains the spinner and on clicking any item of spinner Toast with that course name will be shown.\u00a0\nCreating the activities: There will be one activity and hence one XML file for MainActivity. activity_main.xml: XML file for first activity consists of constraint layout with spinner widget. Below is the code for the XML file for activity:\n\n\nXML\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\u00a0\n \n\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\u00a0\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nCreating the Java and Kotlin file: There is one activity and hence one Java/Kotlin file for the MainActivity file. Java/Kotlin file for Main Activity, in which Array Adapter is used to bind data to the spinner. We will fill data in the array of strings and bind that data to the spinner. Here is the code:\u00a0\u00a0\n\n\nJava\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport android.support.v7.app.AppCompatActivity; \nimport android.widget.AdapterView; \nimport android.view.View; \nimport android.os.Bundle; \nimport android.widget.ArrayAdapter; \nimport android.widget.Spinner; \nimport android.os.Bundle; \n\u00a0\n// Main Activity implements Adapter view \npublic class MainActivity \n\u00a0\u00a0\u00a0\u00a0extends AppCompatActivity \n\u00a0\u00a0\u00a0\u00a0implements AdapterView.OnItemSelectedListener { \n\u00a0\n\u00a0\u00a0\u00a0\u00a0// create array of Strings \n\u00a0\u00a0\u00a0\u00a0// and store name of courses \n\u00a0\u00a0\u00a0\u00a0String[] courses = { \"C\", \"Data structures\", \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"Interview prep\", \"Algorithms\", \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"DSA with java\", \"OS\" }; \n\u00a0\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0protected void onCreate(Bundle savedInstanceState) \n\u00a0\u00a0\u00a0\u00a0{ \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main); \n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Take the instance of Spinner and \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// apply OnItemSelectedListener on it which \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// tells which item of spinner is clicked \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Spinner spino = findViewById(R.id.coursesspinner); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0spin.setOnItemSelectedListener(this); \n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Create the instance of ArrayAdapter \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// having the list of courses \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ArrayAdapter ad \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0= new ArrayAdapter( \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0android.R.layout.simple_spinner_item, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courses); \n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// set simple layout resource file \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// for each item of spinner \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ad.setDropDownViewResource( \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0android.R.layout \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.simple_spinner_dropdown_item); \n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Set the ArrayAdapter (ad) data on the \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Spinner which binds data to spinner \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0spino.setAdapter(ad); \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\n\u00a0\u00a0\u00a0\u00a0// Performing action when ItemSelected \n\u00a0\u00a0\u00a0\u00a0// from spinner, Overriding onItemSelected method \n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0public void onItemSelected(AdapterView<*> arg0, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0View arg1, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int position, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0long id) \n\u00a0\u00a0\u00a0\u00a0{ \n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// make toastof name of course \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// which is selected in spinner \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Toast.makeText(getApplicationContext(), \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courses[position], \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Toast.LENGTH_LONG) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.show(); \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0public void onNothingSelected(AdapterView<*> arg0) \n\u00a0\u00a0\u00a0\u00a0{ \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Auto-generated method stub \n\u00a0\u00a0\u00a0\u00a0} \n} \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nKotlin\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport android.os.Bundle\nimport android.view.View\nimport android.widget.AdapterView\nimport android.widget.AdapterView.OnItemSelectedListener\nimport android.widget.ArrayAdapter\nimport android.widget.Spinner\nimport android.widget.Toast\nimport androidx.appcompat.app.AppCompatActivity\n\u00a0\nclass MainActivity : AppCompatActivity(), OnItemSelectedListener {\n\u00a0\u00a0\u00a0\u00a0// create array of Strings\n\u00a0\u00a0\u00a0\u00a0// and store name of courses\n\u00a0\u00a0\u00a0\u00a0var courses = arrayOf(\"C\", \"Data structures\",\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"Interview prep\", \"Algorithms\",\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"DSA with java\", \"OS\")\n\u00a0\n\u00a0\u00a0\u00a0\u00a0override fun onCreate(savedInstanceState: Bundle?) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main)\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Take the instance of Spinner and\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// apply OnItemSelectedListener on it which\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// tells which item of spinner is clicked\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val spin = findViewById(R.id.coursesspinner)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0spin.onItemSelectedListener = this\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Create the instance of ArrayAdapter\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// having the list of courses\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val ad: ArrayAdapter<*> = ArrayAdapter(\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this,\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0android.R.layout.simple_spinner_item,\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courses)\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// set simple layout resource file\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// for each item of spinner\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ad.setDropDownViewResource(\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0android.R.layout.simple_spinner_dropdown_item)\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Set the ArrayAdapter (ad) data on the\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Spinner which binds data to spinner\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0spin.adapter = ad\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0override fun onItemSelected(parent: AdapterView<*>?, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0view: View, position: Int, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0id: Long) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// make toastof name of course\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// which is selected in spinner\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Toast.makeText(applicationContext,\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courses[position],\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Toast.LENGTH_LONG)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.show()\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0override fun onNothingSelected(parent: AdapterView<*>?) {}\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nOutput:\u00a0\n\n\n" + }, + { + "text": "\nCroller in Android\n\n\nIn this article, we will learn about how to add Croller in android. Croller is used to implement circular Seekbar in android. Seekbar is a type of progress bar. We can drag the seekbar from left to right and vice versa and hence changes the current progress. This is how a Croller look like.\n\nTable of Attributes\n\n\n\n\nXML Attribute\nJava set method\nFunctionality\n\n\nanticlockwise\nsetAntiClockwise(boolean anticlockwise)\nSet the direction of rotation\n\n\nprogress\nsetProgress(int progress)\nSet the current progress of the seekbar\n\n\nlabel\nsetLabel(String str)\nSet the label\n\n\nlabel_size\nsetLabelSize(int size)\nSet the label size\n\n\nlabel_color\nsetLabelColor(int color)\nSet the label color\n\n\nis_continuous\nsetIsContinuous(boolean bool)\nSet whether seekbar is conitnuous or discrete\n\n\nmax\nsetMax(int max)\nSet the maximum value of the seekbar\n\n\nmin\nsetMin(int min)\nSet the minimum value of the seekbar (Default is 1)\n\n\nstart_offset\nsetStartOffset(int offset)\nSet the seekbar start offset angle from bottom horizontal center\n\n\nsweep_angle\nsetSweepAngle(int angle)\nSet the total angle covered by the seekbar\n\n\nprogress_primary_stroke_width\nsetProgressPrimaryStrokeWidth(float width)\nSet the primary progress thickness for continuous type\n\n\nprogress_secondary_stroke_width\nsetProgressSecondaryStrokeWidth(float width)\nSet the secondary progress thickness for continuous type\n\n\nprogress_primary_circle_size\nsetProgressPrimaryCircleSize(float size)\nSet the primary progress circle size for discrete type\n\n\nprogress_secondary_circle_size\nsetProgressSecondaryCircleSize(float size)\nSet the secondary progress circle size for discrete type\n\n\nindicator_width\nsetIndicatorWidth(float width)\nSet the progress indicator width\n\n\nindicator_color\nsetIndicatorColor(int color)\nSet the progress indicator color\n\n\nprogress_primary_color\nsetProgressPrimaryColor(int color)\nSet the progress primary(active) color\n\n\nprogress_secondary_color\nsetProgressSecondaryColor(int color)\nSet the progress secondary(inactive) color\n\n\nprogress_radius\n\u00a0setProgressRadius(float radius)\nSet the radius of the progress arc\n\n\nmain_circle_radius\nsetMainCircleRadius(float radius)\nSet the main(front) circle radius\n\n\nback_circle_radius\nsetBackCircleRadius(float radius)\nSet the back circle radius\n\n\nmain_circle_color\nsetMainCircleColor(int color)\nSet the main(front) circle color\n\n\nback_circle_color\nsetBackCircleColor(int color)\nSet the back circle color\n\n\n\n\nGetting Started\nStep 1: Add the support Library in build.gradle file and add dependency in the dependencies section. \nimplementation \u2018com.sdsmdg.harjot:croller:1.0.7\u2019\nStep 2: Add the following code in activity_main.xml file. In this file we add our Croller to the layout.\n\n\nactivity_main.xml\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\u00a0\u00a0\u00a0\n \n \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStep 3: Add the following code in MainActivity.java file. In this we add setOnCrollerChangeListener() to our croller so whenever there is a change in progress setOnCrollerChangeListener() get invoked automatically.\n\n\nMainActivity.xml\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\u00a0\u00a0\u00a0\npackage org.geeksforgeeks.croller \n\u00a0\u00a0\nimport androidx.appcompat.app.AppCompatActivity; \nimport android.os.Bundle; \nimport android.widget.Toast; \nimport com.sdsmdg.harjot.crollerTest.Croller; \nimport com.sdsmdg.harjot.crollerTest.OnCrollerChangeListener; \n\u00a0\u00a0\npublic class MainActivity extends AppCompatActivity { \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0protected void onCreate(Bundle savedInstanceState) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Croller croller = findViewById(R.id.croller); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// when there is a change in the progress of croller \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// this function get invoked automatically \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0croller.setOnCrollerChangeListener( \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new OnCrollerChangeListener() { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public void onProgressChanged(Croller croller, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int progress) { \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// when the user is starting to change the progress \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// this function gets invoked automatically. \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public void onStartTrackingTouch(Croller croller) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Toast.makeText(MainActivity.this,\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"Start\", Toast.LENGTH_SHORT).show(); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// when the user stops to change the progress \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// this function gets invoked automatically. \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public void onStopTrackingTouch(Croller croller) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Toast.makeText(MainActivity.this,\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"Stop\", Toast.LENGTH_SHORT).show(); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0} \n} \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nRun as Emulator\n\nhttps://media.geeksforgeeks.org/wp-content/uploads/20200715023056/Record_2020-07-15-02-25-47_0cc885b908a72922f1be7b6d493c5de01.mp4\n\n" + }, + { + "text": "\nrunBlocking in Kotlin Coroutines with Example\n\n\nPrerequisite:\n\nKotlin Coroutines on Android\nSuspend Function In Kotlin Coroutines\n\nAs it is known that when the user calls the delay() function in any coroutine, it will not block the thread in which it is running, while the delay() function is called one can do some other operations like updating UI and many more things. As the delay function is a suspend function it has to be called from the coroutine or another suspend function.\nDefinition of runBlocking() function\u00a0\nAccording to official documentation, the runBlocking() function\u00a0may be defined as:\n\nrunBlocking is a coroutine function. By not providing any context, it will get run on the main thread.Runs a new coroutine and blocks the current thread interruptible until its completion. This function should not be used from a coroutine. It is designed to bridge regular blocking code to libraries that are written in suspending style, to be used in main functions and in tests.\n\n\n\nKotlin\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n// sample program in android studio to demonstrate coroutines \npackage com.example.gfgcoroutines \n\u00a0\u00a0\nimport androidx.appcompat.app.AppCompatActivity \nimport android.os.Bundle \nimport android.util.Log \nimport android.widget.Toast \nimport kotlinx.coroutines.GlobalScope \nimport kotlinx.coroutines.delay \nimport kotlinx.coroutines.launch \n\u00a0\u00a0\nclass MainActivity : AppCompatActivity() { \n\u00a0\u00a0\u00a0\u00a0val TAG:String=\"Main Activity\"\n\u00a0\u00a0\u00a0\u00a0override fun onCreate(savedInstanceState: Bundle?) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0GlobalScope.launch(Dispatchers.Main) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0delay(3000) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"User is in the Global Scope \") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Toast.makeText(applicationContext,\"User is in the Global Scope \",Toast.LENGTH_SHORT).show() \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"User is not in the Global Scope \") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Toast.makeText(applicationContext,\"User is not in the Global Scope \",Toast.LENGTH_SHORT).show() \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nLog Output:\nLog-Output of the above program (Timestamps in seconds is shown by Oval Circle in image)\n\nAs it can be seen in the log-output that the \u201cUser is in the Global Scope\u201d gets printed after the Log of \u201cUser is not in the Global Scope\u201d which shows that the GlobalScope start a coroutine, which does not block the main thread, and the other operations can be performed while the delay time get\u2019s over. But when someone wants to call only the suspend function and do not need the coroutine behavior, one can call the suspend function from the runBlocking. So when one wants to call any suspend functions such as delay() and do not care about the asynchronous nature, one can use the runBlocking function. The difference between the calling the suspend function from the GlobalScope.launch{ } and calling the suspend function (eg delay()) from runBlocking{ } is that runBlocking will block the main thread or the thread in which it is used and GlobalScope.launch{ } will not block the main thread, in this case, UI operations can be performed while the thread is delayed.\nAnother use-case of runBlocking is for testing of the JUnit, in which one needs to access the suspend function from within the test function. One case also uses the runBlocking in order to learn the coroutines in-depth in order to figure out how they work behind the scenes. Let\u2019s see from the examples below how runBlocking actually works:\n\n\nKotlin\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\npackage com.example.gfgcoroutines \nimport androidx.appcompat.app.AppCompatActivity \nimport android.os.Bundle \nimport android.util.Log \nimport android.widget.Toast \nimport kotlinx.coroutines.GlobalScope \nimport kotlinx.coroutines.delay \nimport kotlinx.coroutines.launch \n\u00a0\u00a0\nclass MainActivity : AppCompatActivity()\u00a0 \n{ \n\u00a0\u00a0\u00a0\u00a0val TAG=\"Main Activity\"\n\u00a0\u00a0\u00a0\u00a0override fun onCreate(savedInstanceState: Bundle?)\u00a0 \n\u00a0\u00a0\u00a0\u00a0{ \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"Before run-blocking\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0runBlocking\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"just entered into the runBlocking \") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0delay(5000) \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"start of the run-blocking\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"End of the runBlocking\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"after the run blocking\") \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nLog Output:\nLog-Output of the above program \u00a0(Timestamps in seconds is shown by Oval Circle in image)\n\nThe Round oval circle in the above log-output shows the timestamps in which the log output is being printed. It can be clearly seen that when the \u201cjust entered into the runBlocking\u201d the delay of 5 sec is encountered, so other operations can not be performed and have to wait for 5 seconds. The Log statement \u201cafter the run blocking\u201d which is outside of the runBlocking function too, has to wait for the whole runBlocking function to finish its work. Let\u2019s take another example and try to learn how runBlocking works and how different coroutines can be launched within it.\n\n\nKotlin\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\npackage com.example.gfgcoroutines \nimport androidx.appcompat.app.AppCompatActivity \nimport android.os.Bundle \nimport android.util.Log \nimport android.widget.Toast \nimport kotlinx.coroutines.GlobalScope \nimport kotlinx.coroutines.delay \nimport kotlinx.coroutines.launch \n\u00a0\u00a0\nclass MainActivity : AppCompatActivity()\u00a0 \n{ \n\u00a0\u00a0\u00a0\u00a0val TAG=\"Main Activity\"\n\u00a0\u00a0\u00a0\u00a0override fun onCreate(savedInstanceState: Bundle?)\u00a0 \n\u00a0\u00a0\u00a0\u00a0{ \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"Before run-blocking\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0runBlocking\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"just entered into the runBlocking \") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0delay(5000) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0launch(Dispatchers.IO) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0delay(3000L) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"Finished to coroutine 1\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0launch(Dispatchers.IO) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0delay(3000L) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"Finished to coroutine 2\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"start of the run-blocking\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"End of the runBlocking\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"after the run blocking\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0GlobalScope.launch\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Log.d(TAG,\"Logging in the globalScope\") \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nLog Output:\nLog-Output of the above program \u00a0(Timestamps in seconds is shown by Oval Circle in image)\n\nIt can be seen in the above log-output that both GlobalScope and launch will execute after the delay of runBlocking. As both the coroutine which are launched within runBlocking with launch function will be executed within the same thread, it seems like both the coroutine are running in parallel, but it is not possible since both are running in the same thread, but they are running in an asynchronous manner. So it can be said that users should use coroutine runBlocking only when the user wants to do a JUnit test or want to call only the suspend functions.\n\n" + }, + { + "text": "\nBehaviour Components of Android Jetpack\n\n\nAndroid Jetpack is a set of software components, libraries, tools, and guidance to help in developing robust Android applications. Launched by Google in 2018, Jetpack comprises existing android support libraries, android architecture components with an addition of the Android KTX library as a single modular entity. Nowadays, nearly 99% of the apps present on the Google Play Store uses Android Jetpack libraries. The behavior area of the android jetpack covers those libraries that enable users to interact with the application through the UI. This component integrates the standard Android services like notification, downloading, permissions, sharing, assistant, etc. This article explains each and every library of the Behavior component in detail. Jetpack consist of a wide collection of libraries that are built in a way to work together and make robust mobile applications. Its software components have been divided into 4 categories:\n\nFoundation Components\nArchitecture Components\nBehavior Components\nUI Components\n\nFurther, the following are the list of all Behavior components:\n\nDownloadManager\nMedia & Playback\nPermissions\nNotifications\nSharing\nSlices\n\nWays to include Android Jetpack libraries in the application\n\nAdd google repository in the build.gradle file of the application project.\n\n\nallprojects {\n\u00a0repositories {\n\u00a0 \u00a0 \u00a0google()\n\u00a0 \u00a0 \u00a0jcenter()\n\u00a0 \u00a0 \u00a0}\n}\n\n\nAll Jetpack components are available in the Google Maven repository, include them in the build.gradle file\n\n\nallprojects {\n\u00a0repositories {\n\u00a0 \u00a0 \u00a0jcenter()\n\u00a0 \u00a0 \u00a0maven { url \u2018https://maven.google.com\u2019 }\n\u00a0 \u00a0 \u00a0 }\n}\n\nBehavior Components\n1. Download Manager\nThe DownloadManager is a system service in Android that helps in downloading bulky files in the background thread. The ability of mobile devices to download and store files locally is very important and necessary because it is not very appealing to users to keep their internet on all the time. Moreover, continuous internet usage drains the battery of devices faster and leads to increased cost. DownloadManager class handle only HTTP downloads, and it is responsible for avoiding connectivity problems, for resume downloading if the device reboot and mechanism to retry if the file crashes. Since it is a system service, users can simply start a download and listen for a broadcast event to handle the finished download.\na. Initializing the DownloadManager\nLike any other system service, the DownloadManager is initialize using the getSystemService() method. The resultant object is then cast into the DownloadManager class.\n\nprivate void initializeDownloadManager() {\n\u00a0 \u00a0 \u00a0 \u00a0downloadManager= (DownloadManager) getSystemService(DOWNLOAD_SERVICE);\n\u00a0 \u00a0}\n\nb. Creating a download request\nThe HTTP request of the user is defined in the Request class which is an inner class of DownloadManager. \u00a0\n\nDownloadManager.Request request=new\u00a0\nDownloadManager.Request(Uri.parse(\u201chttps://media.geeksforgeeks.org/wp-content/cdn-uploads/gfg_200x200-min.png\u201d));\n\u00a0 \u00a0 \u00a0 \u00a0request.setTitle(\u201cGfG_logo\u201d)\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0.setDescription(\u201cFile is downloading\u2026\u201d)\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0.setDestinationInExternalFilesDir(this,\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0Environment.DIRECTORY_DOWNLOADS,fileName)\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);\n\nc. Enqueue a Download\nTo enqueue a download(adding a download request to the queue of the download manager), the enqueue() method is used. This queue is processed automatically by the system and it returns a download ID.\n\ndownLoadId=downloadManager.enqueue(request);\n\nd. Remove/Delete a downloaded file:\nIn order to remove/delete a downloaded file from the download manager, the remove() method is called and the download ID of the file is passed into it as an argument. \u00a0\n\n\u00a0 private void deleteDownloadedFile(){\n\u00a0 \u00a0 \u00a0 \u00a0downloadManager.remove(downLoadId);\n\u00a0 \u00a0}\n\n2. Media & Playback\nJetpack provides a backward-compatible API for the Android multimedia framework. The included Media libraries facilitate developers to integrate audio, video, and image files into an application. Further, the Playback libraries allow android apps to playback video and audio using sessions and media controllers. The MediaPlayer APIs can access and play media files from the application\u2019s resources(raw resources), from standalone files in the filesystem, or from a data stream coming through a network connection. Below mentioned classes are used to play sound and video in the Android framework:\n\nMediaPlayer: Primary API responsible for playing audio and video\nAudioManager: Manage audio sources and audio output(volume control) on the device.\n\nThe Android framework provides a variety of options to the developers on the use of the type of media players in an application:\n\nMedia Player: This is a clean player having basic functionalities and it supports the most commonly used audio-video formats as well as data sources. The simple and easy to use interface of this player makes it suitable in many uses cases; however, it supports minimal customization.\nExoPlayer: An open-source software that supports high-performance features and adaptive streaming technology like DASH and HLS.\nYouTube: For those use cases in which an app plays videos precisely from the YouTube platform, developers consider integrating this API.\nCustom Media Player: In order to design a fully customized media player that fulfills the exact need for an application, one can use low-level media APIs such as MediaCodec, MediaDRM, and AudioTrack.\n\nTo design an application using MediaPlayer, some appropriate declaration has to be made in the manifest file to use the associated features.\na. To stream any network-based content using MediaPlayer, the app must request network access\n\n\n\nb. To prevent the screen from dimming or the processor from sleeping while an application is running a MediaPlayer, the app must request Wake Lock permission\n\n\n\n3. Permissions\nThis area of the Behavior component accommodates a permission system along with a set of predefined permissions for certain tasks in the Android apps. Almost every application request some permissions from the user. For example, if an application requires network access to carry out a task, it will define permission for the user. Developers declare the permissions for an application in its manifest file and the code must handle both the situations i.e., acceptance as well as denial of the requested permission by the user. Moreover, this file can also define additional permissions that will be used to restrict access to particular components.\nThe concept of asking permission in the Android system has changed significantly after API 23. Initially, the applications ask for all the permissions from the user at the time of installation. After the release of API level 23, the applications seek permissions during runtime. With this new model of permission in the Android system, users can grant one-time permission to an app for a certain task rather than selecting \u201callow always\u201d. There are different levels present in the system permissions, one of them is protection levels. Following are the two important protection level for any permission:\n\nNormal: The set of permissions that falls in this category are safe in terms of users\u2019 privacy as well as carrying out tasks that require the involvement of other applications. This type of permission is granted to the application by default. To set a time zone for a device/application is an example of normal permissions.\nDangerous: This class of permissions targets user\u2019s private information, for example, permission to read user\u2019s contact data. These permissions have the potential to affect the operations of other applications as well. Generally, the app asks for dangerous permissions during runtime.\n\nPermission groups: Dangerous permissions that seek the user\u2019s choice to grant or deny it are classified into 9 groups. The purpose of doing such type of grouping is to facilitate users to grant all the permissions required by a component with a single action instead of selecting one by one. For example, it is convenient for users to grant all permissions related to the editing of contacts at once rather than granting access separately to view, edit, and add contacts. Following is the table of permission groups:\n\n\n\n\n\nPermission\n\n\nGroup Description\n\n\n\n\n\nCalendar\nManaging calendars\n\n\nContacts\nManaging contacts\n\n\nLocation\nCurrent device location\n\n\nCamera\nTaking photos and recording videos\n\n\nPhone\nDialing and managing phone calls\n\n\nSMS\nSending and viewing messages\n\n\nMicrophone\nAudio recording\n\n\nStorage\nAccessing photos, media, and files\n\n\nBody Sensors\nPulse rate, heart rate, and similar kind of data\n\n\n\n\n4. Notifications\nGenerating a notification is one of the most beneficial features of today\u2019s mobile applications. Its prime purpose is to inform the users regarding events happening inside an app. By using it in the correct way, this utility has the capability to elevate user\u2019s motivation on using the application. Android provided the Notification service from the very beginning and it has evolved continuously over the period of time. Developers can accommodate various kinds of images and buttons in the notification area which makes them more expressive. Not only mobile phones but Android TV and wearables also use the notification feature in order to control their media operations. Following are the types of notifications that are generally used:\n\nCommunication from other users\nWell-timed and informative task reminders\n\nWays to inform the users: The device can attract the user\u2019s attention and can inform them regarding the arrived notifications. Following are the ways to do the same:\n\nPlay a sound or vibrate\nShow a status bar icon\nDisplay notification on the lock screen\nBlink the device\u2019s LED\nNotification can peek onto the current screen\n\n5. Sharing\nIn today\u2019s world, humans are very much dependent on mobile applications. Users need to share the day to day important information with their colleagues, family, or friends. This information can be in the form of text, images, or other document files. Thus it is extremely important for the Android apps to have the ability to communicate and integrate with each other. The Sharing division of Behavior component is responsible for sharing and receiving contents with different applications. The ShareActionProvider class is used to carry out the task of sharing contents and information.\u00a0\nIn order to ease the procedure of sharing information across various applications, Android uses Intents and their associated extras. In Android, there are two ways for users by which they can share data between apps:\na. Using Android Share sheet: It is a dialog box that appears on the screen when a user makes a share action request. All the apps available on the device and are compatible with the sharing feature appears on the screen in a sheet-like structure. The main aim of this share sheet is to send information/content outside an app and/or directly to another user.\u00a0\n\nb. Using Android Intent Resolver: It is mainly used for sharing a file within different applications available on the device. For example, opening an email file on the device and asking the user to choose their preferred mail application.\n\n6. Slices\nAndroid provides a new technique to display the remote contents in the form of Slices. It is the UI component that displays the contents from an application to the Google Search app or in different platforms like Google Assistant or Google Assistant devices. Being a part of Jetpack, it has backward compatibility up to Android 4.4(API 19). Developers find this module very beneficial because by making app data available using Slices, a user can find information about that app by using Google Search or Assistant. Further, Android Jetpack facilitates in creating flexible UI templates using Slices that is capable of displaying app data outside the app.\u00a0\nIn the Android project, SliceProvider class allows an application to produce content that will be displayed in system spaces. SliceProvider is the extension of Content Provider and Slices are constructed on the top of the Content providers. Developers can host a variety of slices from an application as it is based on the content URIs. The application will receive a content URI and then select the kind of slice needed to build and present in front of a user. The onBindSlice() method is called when an application needs to display the slice. This method returns the slice-based upon the content URI received as an input. To update the slice notifyChange() method is called. Android search applications like Google Assistant or Google Search are termed as SlicePresenter. Slices are fetched by SlicePresenter by calling System API along with the Slice URI.\u00a0\n\n\n" + }, + { + "text": "\nAdapterViewFlipper in Android with Example\n\n\nThe AdapterViewFlipper class is a subclass of the ViewAnimator class and is used to flip between 2 or more views, such that only one view is displayed at a time. It is commonly used in slides. It is an element of the transition widget which helps to add transitions on the views. It is mainly useful to animate a view on the screen. AdapterViewFlipper switches smoothly between two or more views (TextView, ImageView, or any Layout) and thus provides a way of transitioning from one view to another through appropriate animations. Below is a preview sample of AdapterViewFlipper.\n\nDifference Between ViewFlipper and AdapterViewFlipper\nViewFlipper and AdapterViewFlipper both are subclasses of ViewAnimator. The ViewFlipper is initially used to display all slide views fixed. This means that views will not be recycled. AdapterViewFlipper uses an Adapter to fill data (similar to ListView / Spinner / RecyclerView etc), so the children are determined on the fly and the views representing the children can be recycled. So AdapterViewFlipper is used to display all child views. So there is room for recycling views and loading views dynamically.\nSteps for Creating AdapterViewFlipper\nStep 1: Create a New Project\nTo create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.\nStep 2: Working with activity_main.xml file\nClick on Res -> Layout -> activity_main.xml and add a TextView to display a text and the AdapterViewFlipper to display the functionality. Below is the complete code for the activity_main.xml file.\u00a0\u00a0\n\n\nXML\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStep 3: Create another Layout file\nNow create another XML layouts file by right-clicking on res -> layout -> new -> Layout Resource File and name it as custom_adapter_layout.xml. In this file add an ImageView and TextView to use it in the Adapter. Below is the complete code for the custom_adapter_layout.xml file.\u00a0\u00a0\n\n\nXML\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStep 4: Working with MainActivity.java file\nOpen MainActivity and add the below code to initiate the AdapterViewFlipper. Firstly create two arrays one for images and the other for names. After creating, set the adapter to fill the data in the view. Finally set the auto start and flip interval time so that AdapterViewFlipper switch between the views and the current view will go out and the next view will come in after the given time interval. Below is the complete code for the MainActivity.java file. Refer to the comments inside the code to understand the code.\n\n\nJava\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport android.content.Context; \nimport android.os.Bundle; \nimport android.view.LayoutInflater; \nimport android.view.View; \nimport android.view.ViewGroup; \nimport android.widget.AdapterViewFlipper; \nimport android.widget.BaseAdapter; \nimport android.widget.ImageView; \nimport android.widget.TextView; \nimport androidx.appcompat.app.AppCompatActivity; \n\u00a0\u00a0\npublic class MainActivity extends AppCompatActivity { \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0AdapterViewFlipper adapterViewFlipper; \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0int[] IMAGES = { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0R.drawable.ldeosai, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0R.drawable.lakedudipatsar, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0R.drawable.lrama, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0R.drawable.lakekachura \n\u00a0\u00a0\u00a0\u00a0}; \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0String[] NAMES = { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"Deosai National Park\", \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"Lake Dudipatsar\", \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"Rama Meadows\", \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"Lower Kachura Lake\"\n\u00a0\u00a0\u00a0\u00a0}; \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0protected void onCreate(Bundle savedInstanceState) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Link those objects with their respective id's \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// that we have given in .XML file \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0adapterViewFlipper = (AdapterViewFlipper) findViewById(R.id.adapterViewFlipper); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0CustomAdapter customAdapter = new CustomAdapter(getApplicationContext(), NAMES, IMAGES); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0adapterViewFlipper.setAdapter(customAdapter); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0adapterViewFlipper.setFlipInterval(2600); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0adapterViewFlipper.setAutoStart(true); \n\u00a0\u00a0\u00a0\u00a0} \n} \n\u00a0\u00a0\nclass CustomAdapter extends BaseAdapter { \n\u00a0\u00a0\u00a0\u00a0Context context; \n\u00a0\u00a0\u00a0\u00a0int[] images; \n\u00a0\u00a0\u00a0\u00a0String[] names; \n\u00a0\u00a0\u00a0\u00a0LayoutInflater inflater; \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0public CustomAdapter(Context applicationContext, String[] names, int[] images) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.context = applicationContext; \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.images = images; \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0this.names = names; \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0inflater = (LayoutInflater.from(applicationContext)); \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0public int getCount() { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return names.length; \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0public Object getItem(int position) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return null; \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0public long getItemId(int position) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return 0; \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0public View getView(int position, View view, ViewGroup parent) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0view = inflater.inflate(R.layout.custom_adapter_layout, null); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Link those objects with their respective id's \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// that we have given in .XML file \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0TextView name = (TextView) view.findViewById(R.id.name); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ImageView image = (ImageView) view.findViewById(R.id.image); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Set the data in text view \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0name.setText(names[position]); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Set the image in Image view \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0image.setImageResource(images[position]); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return view; \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nOutput: Run on Emulator\nNow connect your device with a USB cable or an Emulator and launch the application. You will see an Adaptiveflipping of the image will display which will change after a certain millisecond.\u00a0\n\nhttps://media.geeksforgeeks.org/wp-content/uploads/20200830211019/adapter.mp4\n\n" + }, + { + "text": "\nImageButton in Kotlin\n\n\nAndroid ImageButton is a user interface widget which is used to display a button having image and to perform exactly like button when we click on it but here, we add an image on Image button instead of text. There are different types of buttons available in android like ImageButton, ToggleButton etc.\nWe can add an image to the button simply by using attribute android:src in activity_main.xml file or by using setImageResource() method.\nIn android, we can create ImageButton control in two ways either manually or programmatically.\nFirst we create a new project by following the below steps:\n\nClick on File, then New => New Project.\nAfter that include the Kotlin support and click on next.\nSelect the minimum SDK as per convenience and click next button.\nThen select the Empty activity => next => finish.\n\nDifferent attributes of Switch widget\n\n\n\nXML Attributes\nDescription\n\n\n\n\nandroid:id\nUsed to uniquely identify the control.\n\n\nandroid:src\nUsed to specify the source file of the image.\n\n\nandroid:onClick\nUsed to Specifies what to do when this button is clicked.\n\n\nandroid:visibility\nUsed to set visibility of the image button.\n\n\nandroid:background\nUsed to set background color of the Image button.\n\n\nandroid:maxHeight\nUsed to set maximum height of the Image button view.\n\n\nandroid:maxWidth\nUsed to set maximum width of the Image button view.\n\n\nandroid:padding\nUsed to set the padding from left, right, top and bottom.\n\n\n\nUse ImageBotton in activity_main.xml file\nIn this file, we include the Edittext and ImageButton and set their attributes like id, layout_width, hint etc.\n\nXML\n\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nModify the strings.xml file to add application name\n\nXML\n\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\u00a0\u00a0\u00a0\u00a0ImageButtonInKotlin \n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + }, + { + "text": "\nAdding Firebase to Android App\n\n\n There are various services offered online such as storage, online processing, realtime database, authorisation of user etc. Google developed a platform called \nFirebase\n that provide all these online services. It also gives a daily analysis of usage of these services along with the details of user using it. To simplify, it can be said that Firebase is a mobile and web application development platform. It provides services that a web application or mobile application might require. Anyone can easily include firebase to there application and it will make their online work way easier than it was used to be. There are \ntwo ways to add firebase\n to any Android app: \n Using Firebase Assistant Below are the steps to include Firebase to Android project in Android studio: Update the android studio (>= 2.2)Create a new project in the firebase by clicking on the Add project.Now open the android studio and click on Tools in the upper left corner. Now click on the Firebase option in the drop down menu.A menu will appear on the right side of screen. It will show various services that Firebase offers. Choose the desired service.Now Click on the Connect to Firebase option in the menu of desired service.Add the dependencies of your service by clicking on the Add [YOUR SERVICE NAME] to the app option. (In the image below, the Firebase cloud messaging service is chosen) Manually adding firebase In this, the steps involve: Create a firebase project Create a project by clicking on create project in the firebase console.Fill the necessary details in the pop up window about the project. Edit the project ID if required.Click on create project to finally create it.Now add this project to the android app Click on the Add firebase to your android app option on the starting window.\n\nA prompt will open where to enter the package name of the app. Now the app is connected to the Firebase. Now all the cloud based as well server based services can be easily used in the app.Now the app will be registered with firebase.Also, the SHA1 certificate, can be given, of the app by following steps: Go to android studio project\u00a0\u21b3 gradle\u00a0\u00a0\u00a0\u21b3 root folder\u00a0\u00a0\u00a0\u00a0\u00a0\u21b3 Tasks\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u21b3 Android\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u21b3 signingReport\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u21b3 copy paste SHA1 from consoleNow download the google-services.json file and place it in the root directory of the android app.Now add the following in the project. Adding the sdk in the project. Add the following code to the PROJECT-LEVELbuild.gradle of the app. \nXML\n\nbuildscript {\n dependencies {\n classpath 'com.google.gms:google-services:4.0.0'\n }\n}\n\nAdd the following code to APP-LEVEL build.gradle of the app. \nXML\n\ndependencies {\n compile 'com.google.firebase:firebase-core:16.0.0'\n}\n...\n// Add to the bottom of the file\napply plugin: 'com.google.gms.google-services'\n\nNow Sync the gradle by clicking on sync now.After adding the above code(sdk), run the app to send the verification to the Firebase console.Firebase is now successfully installed.\n\n" + }, + { + "text": "\nHow to Create a New Fragment in Android Studio?\n\n\nAndroid Studio is the official integrated development environment for Google\u2019s Android operating system, built on JetBrains\u2019 IntelliJ IDEA software and designed specifically for Android development. You can Develop Android App using this. Here, We are going to learn how to create a new Fragment in Android Studio. A Fragment is a piece of an activity that enables a more modular activity design. A fragment is easier to reuse within activities and layouts. Android devices have a variety of screen sizes and densities. It simplifies the reuse of components in different layouts and their logic. We can also use fragments also to support different layouts for landscape and portrait orientation on a smartphone.\nStep by Step Implementation\nStep 1: Create a New Project in Android Studio\nTo create a new project in Android Studio please refer to\u00a0How to Create/Start a New Project in Android Studio. The code for that has been given in both Java and Kotlin Programming Language for Android.\nStep 2: Create New Fragment\nRight-Click on the First button inside Java, then click on New.\n\nThen Go to Fragment.\n\nThe next step is to choose the Fragment type.\nFragment in Android refers to a single screen with a user interface. For Beginners, \u201cBlank Fragment\u201d is recommended).\u00a0\nClick on Fragment(Blank).\n\nNow, A new Dialog Box will appear.\nThen, fill in the Fragment Name text field. In Android studio, files named in CamelCase are preferred. An XML file is used to provide functionalities of the user interface for our app. An XML file of the fragment is created using the first word in the fragment name.\nClick on Finish. And you have created your Fragment.\n\n" + }, + { + "text": "\nGridView in Android with Example\n\n\nA GridView is a type of AdapterView that displays items in a two-dimensional scrolling grid. Items are inserted into this grid layout from a database or from an array. The adapter is used for displaying this data, setAdapter() method is used to join the adapter with GridView. The main function of the adapter in GridView is to fetch data from a database or array and insert each piece of data in an appropriate item that will be displayed in GridView. This is what the GridView structure looks like. We are going to\u00a0implement this project using both Java and Kotlin Programming Language for Android.\n\nXML Attributes of GridView\n\nandroid:numColumns: This attribute of GridView will be used to decide the number of columns that are to be displayed in Grid.\nandroid:horizontalSpacing: This attribute is used to define the spacing between two columns of GridView.\nandroid:verticalSpacing: This attribute is used to specify the spacing between two rows of GridView.\n\nStep By Step Implementation\nStep 1: Create a New Project in Android Studio\nTo create a new project in Android Studio please refer to\u00a0How to Create/Start a New Project in Android Studio. The code for that has been given in both Java and Kotlin Programming Language for Android.\nStep 2: Add the Required Dependencies\nAdd the Google Repository to your settings.gradle File.\ndependencyResolutionManagement {\n repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n repositories {\n // add the following\n google()\n mavenCentral()\n }\n}\nAfter adding this Dependency, Sync the Project and now we will move towards its implementation.\nStep 3: Working with the XML Files\nNext, go to the activity_main.xml file, which represents the UI of the project. Below is the code for the\u00a0activity_main.xml file. Comments are added inside the code to understand the code in more detail.\n\n\nXML\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nCreate an XML layout file for each item of GridView\nCreate an XML file for each grid item to be displayed in GridView. Click on the app > res > layout > Right-Click > Layout Resource file and then name the file as card_item. Below is the code for the\u00a0card_item.xml file.\n\n\nXML\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\u00a0\u00a0 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStep 5: Create a Model Class for Storing Data\nModel Class is the Java/Kotlin Class that handles data to be added to each GridView item of GridView. For Creating Model Class.\u00a0\nNow click on app > java > apps package name > Right-Click on it. Then Click on New > Java Class. Name your Java/Kotlin Class file as CourseModel. Below is the code for the java > apps package name > Right-Click on it. Then Click on New > Java Class. Name your Java Class file as CourseGVAdapter. Below is the code for the CourseGVAdapter file.\n\n\nJava\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport android.content.Context; \nimport android.view.LayoutInflater; \nimport android.view.View; \nimport android.view.ViewGroup; \nimport android.widget.ArrayAdapter; \nimport android.widget.ImageView; \nimport android.widget.TextView; \nimport androidx.annotation.NonNull; \nimport androidx.annotation.Nullable; \nimport java.util.ArrayList; \n\u00a0\u00a0\npublic class CourseGVAdapter extends ArrayAdapter { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0public CourseGVAdapter(@NonNull Context context, ArrayList courseModelArrayList) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super(context, 0, courseModelArrayList); \n\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0@NonNull\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0View listitemView = convertView; \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (listitemView == null) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Layout Inflater inflates each item to be displayed in GridView. \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0listitemView = LayoutInflater.from(getContext()).inflate(R.layout.card_item, parent, false); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0CourseModel courseModel = getItem(position); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0TextView courseTV = listitemView.findViewById(R.id.idTVCourse); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ImageView courseIV = listitemView.findViewById(R.id.idIVcourse); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseTV.setText(courseModel.getCourse_name()); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseIV.setImageResource(courseModel.getImgid()); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return listitemView; \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nKotlin\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport android.content.Context \nimport android.view.LayoutInflater \nimport android.view.View \nimport android.view.ViewGroup \nimport android.widget.ArrayAdapter \nimport android.widget.ImageView \nimport android.widget.TextView \n\u00a0\u00a0\nclass CourseGVAdapter(context: Context, courseModelArrayList: ArrayList?) : \n\u00a0\u00a0\u00a0\u00a0ArrayAdapter(context, 0, courseModelArrayList) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var listitemView = convertView \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (listitemView == null) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Layout Inflater inflates each item to be displayed in GridView. \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0listitemView = LayoutInflater.from(context).inflate(R.layout.card_item, parent, false) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val courseModel: CourseModel? = getItem(position) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val courseTV = listitemView!!.findViewById(R.id.idTVCourse) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val courseIV = listitemView.findViewById(R.id.idIVcourse) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseTV.setText(courseModel.getCourse_name()) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseIV.setImageResource(courseModel.getImgid()) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return listitemView \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStep 7: Working with the MainActivity File\nGo to the MainActivity File and refer to the following code. Below is the code for the MainActivity File. Comments are added inside the code to understand the code in more detail.\n\n\nJava\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport android.os.Bundle; \nimport android.widget.GridView; \nimport androidx.appcompat.app.AppCompatActivity; \nimport java.util.ArrayList; \n\u00a0\u00a0\npublic class MainActivity extends AppCompatActivity { \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0GridView coursesGV; \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0protected void onCreate(Bundle savedInstanceState) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0coursesGV = findViewById(R.id.idGVcourses); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ArrayList courseModelArrayList = new ArrayList(); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseModelArrayList.add(new CourseModel(\"DSA\", R.drawable.ic_gfglogo)); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseModelArrayList.add(new CourseModel(\"JAVA\", R.drawable.ic_gfglogo)); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseModelArrayList.add(new CourseModel(\"C++\", R.drawable.ic_gfglogo)); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseModelArrayList.add(new CourseModel(\"Python\", R.drawable.ic_gfglogo)); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseModelArrayList.add(new CourseModel(\"Javascript\", R.drawable.ic_gfglogo)); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseModelArrayList.add(new CourseModel(\"DSA\", R.drawable.ic_gfglogo)); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0CourseGVAdapter adapter = new CourseGVAdapter(this, courseModelArrayList); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0coursesGV.setAdapter(adapter); \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nKotlin\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport android.os.Bundle \nimport android.widget.GridView \nimport androidx.appcompat.app.AppCompatActivity \n\u00a0\u00a0\nclass MainActivity : AppCompatActivity() { \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0private lateinit var coursesGV: GridView \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0override fun onCreate(savedInstanceState: Bundle?) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main) \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0coursesGV = findViewById(R.id.idGVcourses) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val courseModelArrayList: ArrayList = ArrayList() \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseModelArrayList.add(CourseModel(\"DSA\", R.drawable.ic_gfglogo)) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseModelArrayList.add(CourseModel(\"JAVA\", R.drawable.ic_gfglogo)) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseModelArrayList.add(CourseModel(\"C++\", R.drawable.ic_gfglogo)) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseModelArrayList.add(CourseModel(\"Python\", R.drawable.ic_gfglogo)) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseModelArrayList.add(CourseModel(\"Javascript\", R.drawable.ic_gfglogo)) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0courseModelArrayList.add(CourseModel(\"DSA\", R.drawable.ic_gfglogo)) \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val adapter = CourseGVAdapter(this, courseModelArrayList) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0coursesGV.adapter = adapter \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nOutput:\n\u00a0\n\n" + }, + { + "text": "\nSlidingDrawer in Android with Example\n\n\nSlidingDrawer is a common requirement in android mobiles to view the content whenever needed by sliding horizontally as well as vertically. In this article, let us check out Sliding Drawer which is used to hide the content out from the screen and allows the user to drag a handle to bring the content on the screen whenever needed in a very user-friendly way. The sliding drawer is a special widget and it contains two children\u2019s views, one to handle that the user\u2019s drags and the other is content attached to the handle which dragged along with it.\u00a0\nImportant Methods of SlidingDrawer\nAs this is the sliding drawer, we can drag and see the contents whenever necessary. So basically, open and close are the very important methods associated with that. In our example, using that lets us have a small demo code. Besides, those other important methods are also there and they are also discussed here. To initialize(or instantiate) a variable of SlidingDrawer, we need to do like below\n// First initiate the SlidingDrawer, simpleSlidingDrawer1 \nis the id of SlidingDrawer defined in\n// activity_main.xml Here using simpleSlidingDrawer1 as object and \nthis is used throughout next\n\nSlidingDrawer simpleSlidingDrawer1 = (SlidingDrawer) findViewById (R.id.simpleSlidingDrawer1); \n\n\n\n\n\nMethods\n\n\nDescription\n\n\n\n\n\nopen()\nIn order to open the drawer immediately, we open the drawer on View click (Button, TextView, etc)\n\n\nclose()\nIn order to close the drawer immediately, we close the drawer on View click ( Button, TextView, etc)\n\n\nanimateOpen()\n\nThis method is similar to the open() method but with animation.\u00a0\nWe can also use this method on click of a View (Button or any other view)\n\n\n\nanimateClose()\n\nThis method is similar to the close() method but with animation.\u00a0\nWe can also use this method on click of a View (Button or any other view)\n\n\n\nisOpened()\n\nIn many places, we may need to check whether the drawer is open or not.\u00a0\nResultant is a boolean value and if true, the drawer is opened\n\n\n\nlock()\n\nIf there is a necessity to disable the touch events, we can use this method.\u00a0\nThough it is a rare scenario, this facility is also available and\u00a0\nit is used to lock the SliderDrawer and ignores the touch events.\u00a0\nWe can also use this method on click of a View (Button or any other view)\n\n\n\nunlock()\n\nIf accidentally locked i.e. touch events are disabled, it has to be unlocked.\u00a0\nFor that, we can use this method. We can also use this method on click of a View (Button or any other view)\n\n\n\n\n\n// open the Sliding Drawer\nsimpleSlidingDrawer1.open(); \n\n// close the Sliding Drawer\nsimpleSlidingDrawer1.close(); \n\n// open the Sliding Drawer but with an animation\nsimpleSlidingDrawer1.animateOpen(); \n\n// close the Sliding Drawer but with an animation\nsimpleSlidingDrawer1.animateClose(); \nProgrammatically we may need to check whether the SlidingDrawer is opened or closed. For that, we can use the below set of methods.\n// check whether the slider is opened or not and depends\n// upon that we can do rest of the calculations\nBoolean isSliderSrawerOpen = simpleSlidingDrawer1.isOpened(); \n\n// If we do not want touch events to occur, set this\nsimpleSlidingDrawer1.lock(); \n\n// In order to process the touch events if accidentally\n// locked or due to some requirement got locked\nsimpleSlidingDrawer1.unlock();\nSetter Methods\nsetOnDrawerCloseListener(OnDrawerCloseListener onDrawerCloseListener)\nThis method is used to sets the listener that receives the notification when the drawer becomes close. The name of the method is self-explanatory.\u00a0\nsimpleSlidingDrawer1.setOnDrawerCloseListener(\n new SlidingDrawer.OnDrawerCloseListener() {\n @Override public void onDrawerClosed()\n {\n // Suppose you can give a toast message or when\n drawer closes need to\n // navigate to another\n event etc., So required steps are done here\n }\n});\nsetOnDrawerOpenListener(OnDrawerOpenListener onDrawerOpenListener)\nThis method is used to set the listener that receives the notification when the drawer becomes open. The name of the method is self-explanatory.\nsimpleSlidingDrawer1.setOnDrawerOpenListener(\n new SlidingDrawer.OnDrawerOpenListener() {\n @Override public void onDrawerOpened()\n {\n // As per your requirement, add code here\n }\n});\nsetOnDrawerScrollListener(OnDrawerScrollListeneronDrawerScrollListener)\nThis method is used to set the listener that receives the notification when the drawer starts or ends a scroll. The name of the method is self-explanatory.\nsimpleSlidingDrawer1.setOnDrawerScrollListener(\n new SlidingDrawer.OnDrawerScrollListener() {\n @Override public void onScrollStarted() {\n // Scroll is necessary for large data to view,\n so necessary code is required here\n }\n\n @Override public void onScrollEnded()\n {\n // add code here for the scroll ended.\n }\n});\nImportant Attributes of SlidingDrawer\nIn order to identify a SliderDrawer, certain attributes are very mandatory.\u00a0\n\n\n\n\n\nAttributes\n\nDescription\n\n\n\n\nId\n\nThe id attribute is used to uniquely identify a SliderDrawer. In your entire code, with this id,\u00a0\nSliderDrawer is accessed. This is the key field and by keeping meaningful and\u00a0\nuser-friendly names for id, future developers can easily understand and maintain the code\n\n\n\nhandle\n\nThis attribute is used as an Identifier for the child that represents the drawer\u2019s handle.\u00a0\nThis is always visible in the application\n\n\n\ncontent\n\nHere you can define the drawer\u2019s content. In order to make the contents visible,\n\u00a0one can click the handle and see it. open() and close() methods\nare there to make content visible and invisible.\n\n\n\norientation\n\nThe default orientation is vertical. Sometimes there may be a requirement to make\u00a0\nthe orientation to be horizontal. This attribute makes the facility for it.\n\n\n\nrotation\nDepending upon the requirement the view differs. Some prefer to have it in 90/180/270/360 degrees etc.\n\n\n\n\nExample\nLet us see the whole example code for the provided video content. A sample GIF is given below to get an idea about what we are going to do in this article.\nStep by Step Implementation\nStep 1: Create a New Project in Android Studio\nTo create a new project in Android Studio please refer to\u00a0How to Create/Start a New Project in Android Studio. The code for that has been given in both Java and Kotlin Programming Language for Android.\nStep 2: Working with the XML Files\nNext, go to the activity_main.xml file, which represents the UI of the project. Below is the code for the\u00a0activity_main.xml file. Comments are added inside the code to understand the code in more detail.\n\n\nXML\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\u00a0\u00a0 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nCreating a New Layout Resource File\nGo to app > res > layout > right-click > New > Layout Resource File and create a new layout file and name this file as list_item.xml. This XML is going to hold the contents which you are specifying in the ArrayAdapter. Let us declare them in LinearLayout with a vertical orientation so that contents can be scrolled up and down in a vertical direction.\n\n\nXML\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStep 3: Working with the MainActivity File\nGo to the MainActivity File and refer to the following code. Below is the code for the MainActivity File. Comments are added inside the code to understand the code in more detail.\n\n\nJava\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\nimport android.os.Bundle; \nimport android.widget.ArrayAdapter; \nimport android.widget.Button; \nimport android.widget.ListView; \nimport android.widget.SlidingDrawer; \nimport androidx.appcompat.app.AppCompatActivity; \n\u00a0\u00a0\npublic class MainActivity extends AppCompatActivity { \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0String[] nameArray = {\"Bitcoin\", \"Ethereum\", \"Litecoin\", \"IOTA\", \"Libra\", \"Monero\", \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"EOS\", \"NEO\", \"ATOM\", \"Tether\", \"XRP\", \"Bitcoin Cash\", \"Binance Coin\", \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"REN\", \"Bitcoin SV\", \"USD Coin\", \"Stellar\", \"Tezos\", \"Dash\", \"Zcash\"}; \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0@Override\n\u00a0\u00a0\u00a0\u00a0protected void onCreate(Bundle savedInstanceState) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// initiate the SlidingDrawer \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0SlidingDrawer simpleSlidingDrawer1 = findViewById(R.id.simpleSlidingDrawer1); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// initiate a Button which is used for handling the content of SlidingDrawer \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// We can able to have open and close methods for this handleButton \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0final Button handleButton = findViewById(R.id.handle1); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// initiate the ListView that is used for content of SlidingDrawer adapter \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// for the list view. As all are text, it is defined as ArrayAdapter \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Your cryptocurrency items are going to be displayed via this view using \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// below cryptocurrency ArrayAdapter \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ListView simpleListView1 = findViewById(R.id.simpleListView1); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// Below syntax is for defining ArrayAdapter \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ArrayAdapter cryptocurrencyArrayAdapter = new ArrayAdapter<>(getApplicationContext(), R.layout.list_item, R.id.name1, nameArray); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// set an adapter to fill the data in the ListView \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0simpleListView1.setAdapter(cryptocurrencyArrayAdapter); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// implement setOnDrawerOpenListener event, name itself suggests that \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// we need to write code for drawer opening \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0simpleSlidingDrawer1.setOnDrawerOpenListener(() -> { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// When drawer is opened, we may need to indicate user that close option is available, \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// so just setting text to close. But required functionality can be done here \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0handleButton.setText(\"Close\"); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}); \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// implement setOnDrawerCloseListener event, name itself suggests we need to write close events \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0simpleSlidingDrawer1.setOnDrawerCloseListener(() -> { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// if close is done, we should have the option to open. according \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// to the requirement, carry out necessary steps for close \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0handleButton.setText(\"Open\"); \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}); \n\u00a0\u00a0\u00a0\u00a0} \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nKotlin\n\n\n\n\n\n\n\n\n \n\n\n \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\npackage com.gfg.android.examplekotlin \n\u00a0\u00a0\nimport android.os.Bundle \nimport android.widget.ArrayAdapter \nimport android.widget.Button \nimport android.widget.ListView \nimport android.widget.SlidingDrawer \nimport androidx.appcompat.app.AppCompatActivity \n\u00a0\u00a0\nclass MainActivity : AppCompatActivity() { \n\u00a0\u00a0\u00a0\u00a0var nameArray = arrayOf(\"Bitcoin\", \"Ethereum\", \"Litecoin\", \"IOTA\", \"Libra\", \"Monero\", \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"EOS\", \"NEO\", \"ATOM\", \"Tether\", \"XRP\", \"Bitcoin Cash\", \"Binance Coin\", \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"REN\", \"Bitcoin SV\", \"USD Coin\", \"Stellar\", \"Tezos\", \"Dash\", \"Zcash\") \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0override fun onCreate(savedInstanceState: Bundle?) { \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super.onCreate(savedInstanceState) \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0setContentView(R.layout.activity_main) \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// initiate the SlidingDrawer \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val simpleSlidingDrawer1 = findViewById(R.id.simpleSlidingDrawer1) \n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// initiate a Button which is used for handling the content of SlidingDrawer \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0// We can able to have open and close methods for this handleButton \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val handleButton = findViewById