Differences

This shows you the differences between two versions of the page.

Link to this comparison view

mdad:laboratoare:01 [2020/10/07 13:55]
127.0.0.1 external edit
mdad:laboratoare:01 [2020/10/19 14:47] (current)
ioana_maria.culic [Tasks]
Line 1: Line 1:
-===== Laboratorul 01. ===== +====== Lab 1 - Kotlin ====== 
-==== Objectives ==== +===== Objectives ​===== 
-  * Install and use the Android Studio IDE. +  * Introduction to Kotlin 
-  * Use the development process for building Android apps. +  * Data types 
-  * Create a simple ''​Hello World''​ Android project. +  * Control Flow 
-==== Installing Android Studio ==== +  * Functions 
-Android Studio provides a complete integrated development environment (IDE) including an advanced code editor and a set of app templates. In addition, it contains tools for development,​ debugging, testing, and performance that make it faster and easier to develop apps. You can test your apps with a large range of preconfigured emulators or on your own mobile device, build production apps, and publish on the Google Play store.+  * Extension
  
-Android Studio is available for computers running Windows or Linux, and for Macs running macOS. The newest OpenJDK (Java Development Kit) is bundled with Android Studio.+===== Tasks =====
  
-To get up and running with Android Studio, first check the [[https://developer.android.com/studio/#​Requirements|system requirements]] to ensure that your system meets them. The installation is similar for all platforms. Any differences are noted below.+All tasks will be solved in the [[https://play.kotlinlang.org/|Kotlin Playground]].
  
-=== Steps for installation === +<​note>​When a task is done, please share it to the teacher using the //Share// button located ​on the left.</note>
-  - Navigate ​to the [[https://​developer.android.com/​studio/​|Android developers site]] and follow ​the instructions to download and [[https://developer.android.com/studio/install|install Android Studio]]. +
-  - Accept the default configurations for all steps, and ensure that all components are selected for installation. +
-  - After finishing the install, the Setup Wizard will download and install some additional components including the Android SDK. Be patient, this might take some time depending ​on your Internet speed, and some of the steps may seem redundant. +
-  - When the download completes, Android Studio will start, and you are ready to create your first project. +
-=== Installation videos === +
-Below are installation videos for different platforms:​ +
-  * [[https://​developer.android.com/​studio/​install#​windows|Windows installation]] +
-  * [[https://​developer.android.com/​studio/​install#​linux|Linux installation]] +
-  * [[https://​developer.android.com/​studio/​install#​mac|Mac installation]] +
-==== Create a Hello World app ==== +
-=== Create the app project === +
-  - Open Android Studio if it is not already opened. +
-  - In the main **Welcome to Android Studio** window, click **Start a new Android Studio project**. +
-  - In the **Create New Project** window, choose **Empty Activity** for the **Phone or Tablet** and click **Next**: ​          ​{{:​mdad:​laboratoare:​lab01_choose_empty_activity.png?​400|400 }} +
-  - In the **Configure your project** section, enter **Hello World** for the **Application Name**, leave the other settings to their default state{{:​mdad:​laboratoare:​lab01_hello_world_name.png?​400|400 }}+
  
-  - Click **Finish** +  - Write a Kotlin application that displays your name. 
- +  - Write Kotlin function that computes the factorial ​for n in an iterative way (without recursion). 
-Android Studio creates ​folder ​for your projects, and builds the project with [[https://​gradle.org/​|Gradle]] ​(this may take a few moments). +  - Modify the previous function in such a way that is is written as a single expression. 
- +  - Write an operator extension to so that the ''​!n''​ will compute n the factorial of n. (Hint: [[https://kotlinlang.org/docs/reference/operator-overloading.html|Operator Overloading]]) 
-TipSee the [[https://developer.android.com/studio/build/|Configure your build]] developer page for detailed information. +  - Write an Int extension function that computes ​(as Double) the logarithm ​of its parameter in base ''​this''​Use it in two ways
- +    ''​2.log(8.0)''​ 
-You may also see a "Tip of the day" message with keyboard shortcuts and other useful tips. Click Close to close the message. +    ''​2 log 8.0''​ 
- +  - Modify ​the previous task to be able to use the function with Int numbers as well (`2 log 8`
-If you made all the previous steps correctly, you should see something like this:  +  - Make the following example work: 
-{{:​mdad:​laboratoare:​lab01_project_opened.png?​500|500}} +<code kotlin> 
-====Use a virtual device (emulator)==== +data class Complex (var r: Doublevar iDouble) 
-For the Hello World app will use the Android Virtual Device (AVD) manager to create a virtual device ​(also known as an emulatorthat simulates ​the configuration for a particular type of Android device, and use that virtual device to run the appNote that the Android Emulator has additional requirements beyond the basic system requirements for Android Studio. +  
- +fun main () 
-Using the AVD Manager, you define the hardware characteristics of a device, its API level, storage, skin and other properties and save it as a virtual device. With virtual devices, you can test apps on different device configurations (such as tablets and phones) with different API levels, without having to use physical devices. +    ​val ​= Complex (1.0,2.0) 
-===Create an Android virtual device (AVD)=== +    val b = Complex (3.0,4.0) 
-In order to run an emulator on your computer, you have to create a configuration that describes the virtual device. +  
- +    var s1 = + b 
-  - In Android Studio, select **Tools** > **AVD Manager**. Your Virtual Devices screen appears. If you've already created virtual devices, the screen shows them (as shown in the figure below); otherwise you see a blank list.{{:mdad:​laboratoare:​lab01_avd_manager.png?​400|400 }} +    var s2 = a - 
-  Click the **+Create Virtual Device**The **Select Hardware** window appears showing a list of pre configured hardware devicesFor each device, the table provides a column for its diagonal display size (**Size**), screen resolution in pixels (**Resolution**),​ and pixel density (**Density**).{{:​mdad:​laboratoare:​lab01_select_hardware.png?​400|400 }} +    var s3 = a b 
-  Choose a device such as **Nexus 5x** or **Pixel XL**, and click **Next**. The **System Image** screen appears+    var s4 == b 
-  - Click the **Recommended** tab if it is not already selected, and choose which version of the Android system ​to run on the virtual device ​(such as **Oreo**).{{:​mdad:​laboratoare:​lab01_emulator_system_image.png?​400|400 }} +    ​println (s1) 
-  - After choosing a system image, click **Next**. The **Android Virtual Device** (AVD) window appears. You can also change ​the name of the AVD. Check your configuration and click **Finish**. +    ​println (s2) 
-=== Run the app on the virtual device === +    println (s3) 
-Now we will run the Hello World app +    println (s4) 
-  - In Android Studiochoose **Run** > **Run app** or click the Run icon {{:mdad:​laboratoare:​run_app.png?​15|15}} ​ in the toolbar. +
-  - The **Select Deployment Target** window, under **Available Virtual Devices**, select the virtual device, which you just created, and click **OK**{{:​mdad:​laboratoare:​lab01_select_deployment_target.png?​400|400 }} +</​code>​
- +
-The emulator starts and boots just like physical deviceDepending on the speed of your computerthis may take a while. Your app builds, and once the emulator is ready, Android Studio will upload the app to the emulator and run it+
- +
-You should see the Hello World app as shown in the following figure. +
-{{:​mdad:​laboratoare:​lab01_app_running.png?​200|200}} +
- +
-**Tip**: When testing on virtual device, it is good practice to start it up once, at the very beginning of your session. You should not close it until you are done testing your app, so that your app doesn'​t have to go through the device startup process again. To close the virtual device, click the **X** button at the top of the emulator, choose **Quit** from the menu, or press **Control-Q** in Windows or **Command-Q** in macOS. +
- +
-===Bonus=== +
-  - Make the app display your name instead of the Hello World message +
-  - Run the app on a physical device instead of the emulator+
mdad/laboratoare/01.1602068155.txt.gz · Last modified: 2020/10/19 09:05 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0