Differences

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

Link to this comparison view

smd:laboratoare:01 [2020/02/23 22:41]
vasile.cosovanu Edited Task 4 with new Filter Configuration.
smd:laboratoare:01 [2021/03/17 19:58] (current)
adriana.draghici
Line 1: Line 1:
 ===== Lab 01. Introduction ===== ===== Lab 01. Introduction =====
- 
  
 === Resources === === Resources ===
  
-  * Android Studio: ​[[https://​developer.android.com/​studio#top]] +  * [[https://​developer.android.com/​index.html|Android Developers Documentation]] 
-  * Android Developers: ​[[https://​developer.android.com/​index.html]] +  * [[https://​developer.android.com/​guide/​components/​activities/​activity-lifecycle|Android Application Lifecycle]]
- +
-=== Files === +
- +
-{{:​smd:​laboratoare:​loglevel.zip|}}+
  
 +**Prerequisites:​** [[smd:​laboratoare:​00|Lab 0: Setup github and your environment]]
  
-=== Task 0 Setting up the environment ===+The code skeleton used from task#3:  
 +  * [[https://​github.com/​SMD-UPB/labs| Github repository]] 
 +  * {{:​smd:​laboratoare:​loglevel.zip|}}
  
-To install Android Studio on your own machine follow the step here: [[https://​developer.android.com/​studio/​install|Install Android Studio]]. Android Studio should be already installed on the lab workstations. 
  
 === Task 1 - Create and run an application === === Task 1 - Create and run an application ===
  
-Create a new Android Project in Android Studio (**Start a new Android Studio Project**). In the first screen in the **Phone and Tablet** section, choose **Empty Activity**. Next choose a  **Name**. Set **Java** as language. And select **API level 21** or higher. Leave other options as they are and click **Finish**. On the sidebar on the left choose **Project** and open ** java > student.example.com > MainActivity**. This activity is very simple right now but is a fully functional Android application.+Create a new Android Project in Android Studio (**Start a new Android Studio Project**). In the first screen in the **Phone and Tablet** section, choose **Empty Activity**. On the sidebar on the left choose **Project** and open ** java > student.example.com > MainActivity**. This activity is very simple right now but is a fully functional Android application.
  
 Run the project by clicking the green arrow on the toolbar above the editing area, {{:​smd:​laboratoare:​run.png?​20|}}. Android Studio will prompt you to choose a device. Follow the steps in the next task to create a new virtual device. Run the project by clicking the green arrow on the toolbar above the editing area, {{:​smd:​laboratoare:​run.png?​20|}}. Android Studio will prompt you to choose a device. Follow the steps in the next task to create a new virtual device.
  
-=== Task 2 - Creating a virtual device ===+/*=== Task 2 - Creating a virtual device ===
  
 Create a virtual device: Create a virtual device:
Line 42: Line 39:
 ./​Android/​Sdk/​tools/​emulator -accel-check ./​Android/​Sdk/​tools/​emulator -accel-check
 </​code>​ </​code>​
 +*/
  
-=== Task - Add a button ===+=== Task - Add a button ===
  
 When the project has opened the //​MainActivity.java//​ file should be displayed. If not, open it using the **Package Explorer** pane. You will find it in the **src** folder. When the project has opened the //​MainActivity.java//​ file should be displayed. If not, open it using the **Package Explorer** pane. You will find it in the **src** folder.
Line 49: Line 47:
 The Activity should be very simple. It has an **onCreate** method which is called when the Activity gets started. The Activity should be very simple. It has an **onCreate** method which is called when the Activity gets started.
  
-In the onCreate method ​the Activity calls+The ''​onCreate'' ​method:
 <​code>​ <​code>​
 setContentView(R.layout.activity_main);​ setContentView(R.layout.activity_main);​
Line 61: Line 59:
 Go back to MainActivity.java. Go back to MainActivity.java.
  
-Add the following code to the onCreate method. Make sure the //IDs// match the ones in your layout.+Add the following code to the ''​onCreate'' ​method. Make sure the //IDs// match the ones in your layout.
 <code Java> <code Java>
         Button button = findViewById(R.id.button);​ /* make sure the button ID matches */         Button button = findViewById(R.id.button);​ /* make sure the button ID matches */
Line 80: Line 78:
 Run the project again to see the changes. Run the project again to see the changes.
  
-=== Task - Use logcat for debugging ===+=== Task - Use logcat for debugging ===
  
 Select the **Logcat** tab (situated by default in the bottom panel of Android Studio). This panel shows all the log entries written by the Android applications running on connected mobile devices or emulators. ​ Select the **Logcat** tab (situated by default in the bottom panel of Android Studio). This panel shows all the log entries written by the Android applications running on connected mobile devices or emulators. ​
Line 86: Line 84:
 It is possible to filter these log entries: above the logs themselves there is a text entry input which allows textual filtering. It accepts //​Java-style regular expressions//​. To the left of this text field there is a drop-down which allows you to select //​verbosity//​. Choosing a level will only allow messages of that level or higher to be displayed. To the right of the text field there is a drop-down which allows you to create custom filters. Click on it and select //Edit Filter Configuration//​. From here you can create different filters which limit searches scope using //PID://, //Tag://, //Package Name:// or //​Message://​. It is possible to filter these log entries: above the logs themselves there is a text entry input which allows textual filtering. It accepts //​Java-style regular expressions//​. To the left of this text field there is a drop-down which allows you to select //​verbosity//​. Choosing a level will only allow messages of that level or higher to be displayed. To the right of the text field there is a drop-down which allows you to create custom filters. Click on it and select //Edit Filter Configuration//​. From here you can create different filters which limit searches scope using //PID://, //Tag://, //Package Name:// or //​Message://​.
  
-Import the **LogLevel** ​project ​into Android Studio (**File > New > Import Project**) and navigate to the project in the archive. Look over the code. Each button has a method attached which calls a static method from the //Log// class. These methods generate log entries on different levels of importance: //​d=debug//,​ //i=info//, //​w=warning//,​ //​e=error//​.+**Import the LogLevel ​project** into Android Studio (**File > New > Import Project**) and navigate to the project in the archive. Look over the code. Each button has a method attached which calls a static method from the //Log// class. These methods generate log entries on different levels of importance: //​d=debug//,​ //i=info//, //​w=warning//,​ //​e=error//​.
  
 Add another two buttons to the application: ​ Add another two buttons to the application: ​
Line 94: Line 92:
 For the second button if the previous entry was an //assert// entry, then the next entry will also be an //assert// entry. If there is no previously generated log entry, then a //debug// entry will be logged. For the second button if the previous entry was an //assert// entry, then the next entry will also be an //assert// entry. If there is no previously generated log entry, then a //debug// entry will be logged.
  
-=== Task - View weight ===+=== Task - View weight ===
  
 Use the LogLevel project as a start. ​ Use the LogLevel project as a start. ​
Line 104: Line 102:
 The **weight** parameter is used to distribute empty screen space to the elements which need it. First, the layout builder will place all the elements for which the size is easy to determine. Then, the empty space will be distributed to the elements with //weight//, based on their //weight//: if the total //weight// of all elements is 4, an element with a //weight// of 1 will get 1/4 of the empty screen space, an element with 2 //weight// will get 2/4, and so on. The **weight** parameter is used to distribute empty screen space to the elements which need it. First, the layout builder will place all the elements for which the size is easy to determine. Then, the empty space will be distributed to the elements with //weight//, based on their //weight//: if the total //weight// of all elements is 4, an element with a //weight// of 1 will get 1/4 of the empty screen space, an element with 2 //weight// will get 2/4, and so on.
  
-=== Task - Understand Activity Lifecycle === +=== Task - Understand Activity Lifecycle === 
  
 [[https://​developer.android.com/​guide/​components/​activities/​activity-lifecycle|Activity Lifecycle]] [[https://​developer.android.com/​guide/​components/​activities/​activity-lifecycle|Activity Lifecycle]]
Line 135: Line 133:
   - The application is destroyed   - The application is destroyed
  
-=== Task - Use ADB to transfer files and install apps ===+=== Task - Use ADB to transfer files and install apps ===
  
 [[https://​developer.android.com/​studio/​command-line/​adb|Android Debug Bridge, ADB]] [[https://​developer.android.com/​studio/​command-line/​adb|Android Debug Bridge, ADB]]
Line 153: Line 151:
 adb devices adb devices
 </​code>​ </​code>​
 +
 +<​note>​If you have more than 1 device connected when you try to run a command you need to specify the device on which you want the command to run. //adb -s DEVICE_SERIAL <​command>//</​note>​
  
 To get a **shell on the connected device** use: To get a **shell on the connected device** use:
smd/laboratoare/01.1582490477.txt.gz · Last modified: 2020/02/23 22:41 by vasile.cosovanu
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