Differences

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

Link to this comparison view

smd:laboratoare:01 [2021/03/17 18:53]
adriana.draghici
smd:laboratoare:01 [2021/03/17 19:58] (current)
adriana.draghici
Line 3: Line 3:
 === 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 ===+**Prerequisites:​** [[smd:​laboratoare:​00|Lab 0: Setup github and your environment]]
  
-{{:​smd:​laboratoare:​loglevel.zip|}} +The code skeleton used from task#3:  
- +  * [[https://​github.com/​SMD-UPB/​labs| Github repository]] 
- +  * {{:​smd:​laboratoare:​loglevel.zip|}}
-Prerequisites:​ [[smd:​laboratoare:​00|Lab 0: Setup github and your environment]]+
  
  
Line 20: Line 19:
 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 40: 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 47: 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 59: 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 78: 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 84: 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 92: 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 102: 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 133: 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]]
smd/laboratoare/01.1615999992.txt.gz · Last modified: 2021/03/17 18:53 by adriana.draghici
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