This shows you the differences between two versions of the page.
ndk:courses:01 [2014/03/03 16:39] laura.gheorghe |
ndk:courses:01 [2014/11/05 11:54] (current) laura.gheorghe |
||
---|---|---|---|
Line 3: | Line 3: | ||
* Description: General overview of the Android OS, layers and tools | * Description: General overview of the Android OS, layers and tools | ||
* Practical part: Android tools, emulators, ADB, Beacon Mountain | * Practical part: Android tools, emulators, ADB, Beacon Mountain | ||
+ | |||
==== Lecture ==== | ==== Lecture ==== | ||
Line 28: | Line 29: | ||
=== Task 0 - Setting up the environment === | === Task 0 - Setting up the environment === | ||
- | This section is meant you help you set up your enviroment at home. All links are found in the resources. | + | This section is meant you help you set up your environment at home. All links are found in the resources. |
- | There are two ways of setting up your environment. The first way is using Intel's Beacon Mountain for Android solution. This sets up your whole enviroment including SDK and NDK and contains some additional profiling tools and HAXM, needed for virtualizing Intel Atom based virtual devices. Run the installer and follow the steps. | + | There are two ways of setting up your environment. The first way is using Intel's Beacon Mountain for Android solution. This sets up your whole environment including SDK and NDK and contains some additional profiling tools and HAXM, needed for virtualizing Intel Atom based virtual devices. Run the installer and follow the steps. |
The second way will set up the bare minimum needed for creating an NDK project. | The second way will set up the bare minimum needed for creating an NDK project. | ||
Line 135: | Line 136: | ||
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> | + | <code Java> |
final Button b1 = (Button) findViewById(R.id.button1); | final Button b1 = (Button) findViewById(R.id.button1); | ||
final TextView tv1 = (TextView) findViewById(R.id.textView1); | final TextView tv1 = (TextView) findViewById(R.id.textView1); | ||
Line 157: | Line 158: | ||
Add another two buttons to the application: one that generates an assert level log entry, and one that repeats the previously generated log entry, but with a higher level of importance, except in the case of assert, which will remain the same. | Add another two buttons to the application: one that generates an assert level log entry, and one that repeats the previously generated log entry, but with a higher level of importance, except in the case of assert, which will remain the same. | ||
+ | |||
+ | === Task 6 - View weight === | ||
+ | |||
+ | Use the LogLevel project as a start. Notice that the EditText box only takes up one line of the screen and there should be some screen space left at the bottom of the screen. Make the EditText box take up all available space. To do this, you should set the weight parameter of the EditText view to 1 (or any integer). | ||
+ | |||
+ | 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 7 - Multiple resources === | ||
+ | |||
+ | In Android you can have multiple resources with the same ID. This allows building a single application for all the languages, screen resolutions or formats, and have the system select the correct resource when running the application. | ||
+ | |||
+ | In the LogLevel project, notice that there is a single **layout** folder. Modify this layout to fit two screen densities: mdpi and hdpi. To do this, rename the folder **layout** to **layout-hdpi** and make a copy of it named **layout-mdpi**. This will allow the system to select the mdpi layout for systems with medium dpi or lower, and the hdpi layout for the rest. Modify the mdpi layout to display the buttons on two columns instead of a single button on each row. Use multiple horizontal LinearLayouts. |